Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please don't delete info.level #173

Closed
doanthai opened this issue Dec 28, 2023 · 2 comments · Fixed by #174
Closed

Please don't delete info.level #173

doanthai opened this issue Dec 28, 2023 · 2 comments · Fixed by #174
Assignees
Labels
agent-nodejs Make available for APM Agents project planning. community lib:winston

Comments

@doanthai
Copy link

Hi,
I just update version @elastic/ecs-winston-format from 1.3.1 to 1.5.0 and see an error about logging in console look like

[AsyncTestWinston] undefined 123 12/28/2023, 3:12:44 PM debug async

In old version, undefined is log level of message. When I check code, I see you delete info.level at bellow code:

info['log.level'] = info.level
// Removing 'level' might cause trouble for downstream winston formatters
// given that https://github.com/winstonjs/logform#info-objects says:
//
// > Every info must have at least the level and message properties:
//
// However info still has a info[Symbol.for('level')] for more reliable use.
delete info.level
info['ecs.version'] = version

Though have Symbol.for('level') but some other transports still read level from info. So can you don't delete level in info object.

@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Dec 28, 2023
trentm added a commit that referenced this issue Jan 4, 2024
Winston's logform docs state that 'info' objects should always
have 'level' and 'message' fields. Some downstream transforms
and transports can rely on this. Instead the 'ecsStringify' will
handle excluding the 'level' field from the stringification.

Closes: #173
@trentm trentm self-assigned this Jan 4, 2024
@trentm trentm removed the triage label Jan 4, 2024
@trentm
Copy link
Member

trentm commented Jan 4, 2024

@doanthai Thanks for the issue! I have a fix started.

trentm added a commit that referenced this issue Jan 4, 2024
Winston's logform docs state that 'info' objects should always
have 'level' and 'message' fields. Some downstream transforms
and transports can rely on this. Instead the 'ecsStringify' will
handle excluding the 'level' field from the stringification.

Closes: #173
@redpanda
Copy link

Hi @trentm,

I ran the basic winston example, and the field level is missing from the logs output in STDOUT. Is this expected? Thank you in advance for your answer.

branch: main

input

node packages/ecs-winston-format/examples/basic.js

output

{"@timestamp":"2024-06-18T12:44:09.359Z","ecs.version":"8.10.0","log.level":"info","message":"hi"}
{"@timestamp":"2024-06-18T12:44:09.360Z","ecs.version":"8.10.0","foo":"bar","log.level":"warn","message":"look out"}
{"@timestamp":"2024-06-18T12:44:09.360Z","ecs.version":"8.10.0","error":{"cause":"Error: the cause\n at Object. (/Users/jleger/Workspaces/work/ecs-logging-nodejs/packages/ecs-winston-format/examples/basic.js:43:40)\n at Module._compile (node:internal/modules/cjs/loader:1364:14)\n at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)\n at Module.load (node:internal/modules/cjs/loader:1203:32)\n at Module._load (node:internal/modules/cjs/loader:1019:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)\n at node:internal/main/run_main_module:28:49","code":42,"message":"boom","stack_trace":"Error: boom\n at Object. (/Users/jleger/Workspaces/work/ecs-logging-nodejs/packages/ecs-winston-format/examples/basic.js:43:13)\n at Module._compile (node:internal/modules/cjs/loader:1364:14)\n at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)\n at Module.load (node:internal/modules/cjs/loader:1203:32)\n at Module._load (node:internal/modules/cjs/loader:1019:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)\n at node:internal/main/run_main_module:28:49","type":"Error"},"log.level":"error","message":"here is an exception boom"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. community lib:winston
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants