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

Quotes around isoTime timestamp #905

Closed
davesteinberg opened this issue Sep 8, 2020 · 5 comments
Closed

Quotes around isoTime timestamp #905

davesteinberg opened this issue Sep 8, 2020 · 5 comments

Comments

@davesteinberg
Copy link

I was playing around with using stdTimeFunctions.isoTime from pino to format the timestamp. But I noticed that when I do this, pino-pretty seems to add quotes around the already formatted string. What's really odd is that if I try to reproduce the problem just with pino-pretty directly, it doesn't happen:

const pino = require("pino");
const prettyFactory = require("pino-pretty");

const logger = pino({ name: "test", timestamp: pino.stdTimeFunctions.isoTime, prettyPrint: true });
logger.info("Hello world");

const m = {
  level: 30,
  time: "2020-09-05T03:33:34.414Z",
  pid: 26631,
  hostname: "pb",
  name: "test",
  msg: "Hello, world!",
};
const pretty = prettyFactory();
console.log(pretty(m));

This outputs:

["2020-09-08T16:40:21.584Z"] INFO  (test/45190 on pb): Hello world
[2020-09-05T03:33:34.414Z] INFO  (test/26631 on pb): Hello, world!

I just can't figure out what's going on.

@jsumners
Copy link
Member

jsumners commented Sep 8, 2020

What does the non-pretty log line from pino look like?

@davesteinberg
Copy link
Author

Removing prettyPrint:

const logger = pino({ name: "test", timestamp: pino.stdTimeFunctions.isoTime });

Yields this:

{"level":30,"time":"2020-09-08T17:38:48.373Z","pid":45785,"hostname":"pb","name":"test","msg":"Hello world"}

@jsumners
Copy link
Member

jsumners commented Sep 8, 2020

image

So it is likely a bug in the way the data is passed from pino to pino-pretty within the pino module itself.

@mcollina
Copy link
Member

mcollina commented Sep 9, 2020

The problem should be around here (I think):

pino/lib/tools.js

Lines 232 to 284 in 742f231

write (chunk) {
const lastLogger = this.lastLogger
const chindings = this.chindings()
var time = this.lastTime
if (time.match(/^\d+/)) {
time = parseInt(time)
}
var lastObj = this.lastObj
var lastMsg = this.lastMsg
var errorProps = null
const formatters = lastLogger[formattersSym]
const formattedObj = formatters.log ? formatters.log(lastObj) : lastObj
const messageKey = lastLogger[messageKeySym]
if (lastMsg && formattedObj && !formattedObj.hasOwnProperty(messageKey)) {
formattedObj[messageKey] = lastMsg
}
const obj = Object.assign({
level: this.lastLevel,
time
}, formattedObj, errorProps)
const serializers = lastLogger[serializersSym]
const keys = Object.keys(serializers)
var key
for (var i = 0; i < keys.length; i++) {
key = keys[i]
if (obj[key] !== undefined) {
obj[key] = serializers[key](obj[key])
}
}
for (key in chindings) {
if (!obj.hasOwnProperty(key)) {
obj[key] = chindings[key]
}
}
const stringifiers = lastLogger[stringifiersSym]
const redact = stringifiers[redactFmtSym]
const formatted = pretty(typeof redact === 'function' ? redact(obj) : obj)
if (formatted === undefined) return
setMetadataProps(dest, this)
dest.write(formatted)
}
.

@github-actions
Copy link

github-actions bot commented Feb 5, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants