-
Notifications
You must be signed in to change notification settings - Fork 8
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
A basic one line format #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! I've left some notes.
One question: should we add some color to each line?
README.md
Outdated
const server = fastify({ | ||
logger: { | ||
transport: "one-line-logger", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transport: "one-line-logger", | |
transport: "@fastify/one-line-logger", |
@@ -0,0 +1,54 @@ | |||
const pretty = require('pino-pretty') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const pretty = require('pino-pretty') | |
'use strict' | |
const pretty = require('pino-pretty') |
test/fastify.test.js
Outdated
@@ -0,0 +1,90 @@ | |||
const { serverFactory, EPOCH, TIME } = require('./helpers') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { serverFactory, EPOCH, TIME } = require('./helpers') | |
'use strict' | |
const { serverFactory, EPOCH, TIME } = require('./helpers') |
test/index.test.js
Outdated
@@ -0,0 +1,31 @@ | |||
const { EPOCH, TIME, MESSAGE_KEY } = require('./helpers') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { EPOCH, TIME, MESSAGE_KEY } = require('./helpers') | |
'use strict' | |
const { EPOCH, TIME, MESSAGE_KEY } = require('./helpers') |
src/index.js
Outdated
const second = dateObject.getSeconds() | ||
const milliSecond = dateObject.getMilliseconds() | ||
|
||
const time = `${year}-${month}-${date} ${hour}:${minute}:${second}.${milliSecond}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the timezone could be useful here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about changing it to this then?
Z YYYY-MM-dd HH:mm:ss.SSS - <level> - <method> <route path> - <message>
It will be like this
GMT+0800 2017-02-14 20:51:48.000 - info - request completed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I mean the timezone offset:
2017-02-14 20:51:48.000+08:00 - info - request completed
This format should be compliant to the ISO 8601
https://www.w3.org/TR/NOTE-datetime
level: number; | ||
req?: Request; | ||
}; | ||
export declare const messageFormatFactory: (colorize: boolean) => (log: LogDescriptor, messageKey: string) => string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed colorizerFactory
is exported in the pino-pretty
js file but not in the ts definition file.
Do we not want to expose the messageFormatFactory
, Request
& LogDescriptor
too? But only export target
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed colorizerFactory is exported in the pino-pretty js file but not in the ts definition file.
PR to pino-pretty?
Also updated the PR description for the timezone and color! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last two comment, then LGTM
Nice work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@mcollina ops sorry pushed a commit about readme. 😓 can you help run check again? |
closes fastify/fastify#4027
How does the log look like
The logs look like this:
Unit tests
The following unit tests are included:
messageFormat
logDescriptor
without thereq
objectlogDescriptor
with thereq
objectI believe without doing anything, we have already allowed the following usage:
It's because
pino
usesrequire.resolve('one-line-logger')
to look for the path to main file of this package.Checklist
npm run test
and the Code of conduct