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

Formatting example breaks console substition #106

Open
biergit opened this issue Jun 10, 2021 · 5 comments
Open

Formatting example breaks console substition #106

biergit opened this issue Jun 10, 2021 · 5 comments

Comments

@biergit
Copy link
Contributor

biergit commented Jun 10, 2021

  formatter: function (messages, context) {
    // prefix each log message with a timestamp.
    messages.unshift(new Date().toUTCString());
  },
});

will break: logger.log('Hello %s', 'Jonny')

@jonnyreeves
Copy link
Owner

jonnyreeves commented Jun 10, 2021 via email

@biergit
Copy link
Contributor Author

biergit commented Jun 16, 2021

Sorry, I am no JS expert. This is what I did:

formatter: function (messages, context) {
    const first = messages[0]
    if (messages[0]) {
      messages[0] = new Date().toUTCString() + ' ' + first
    }
  }

It also feels surprising that messages here is not an array but an arguments.

@xhyrom
Copy link

xhyrom commented Dec 18, 2021

Thanks for raising this issue. Do you have a suggested fix? Jonny

On Thu, 10 Jun 2021, 08:46 biergit, @.***> wrote: formatter: function (messages, context) { // prefix each log message with a timestamp. messages.unshift(new Date().toUTCString()); }, }); will break: logger.log('Hello %s', 'Jonny') — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#106>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQ36LX7IZ2QM66YJ7GXHTTSBUWRANCNFSM46NRGWGA .

Why?

The console.log function parses these "variables" like %s only in the first argument, and you put what you want in the formatters in the first argument, and that's not good. The solution is that you add it to the null element at the beginning in your own formatting handler.

@jonnyreeves
Copy link
Owner

jonnyreeves commented Dec 18, 2021 via email

@xhyrom
Copy link

xhyrom commented Jan 3, 2022

Pull requests welcome! ♥️

On Sat, 18 Dec 2021, 13:06 Hyro, @.> wrote: Thanks for raising this issue. Do you have a suggested fix? Jonny … <#m_8893153787719601507_> On Thu, 10 Jun 2021, 08:46 biergit, @.> wrote: formatter: function (messages, context) { // prefix each log message with a timestamp. messages.unshift(new Date().toUTCString()); }, }); will break: logger.log('Hello %s', 'Jonny') — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < #106 <#106>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQ36LX7IZ2QM66YJ7GXHTTSBUWRANCNFSM46NRGWGA . Why? The console.log function parses these "variables" like %s only in the first argument, and you put what you want in the formatters in the first argument, and that's not good. The solution is that you add it to the null element at the beginning in your own formatting handler. — Reply to this email directly, view it on GitHub <#106 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQ36KY2AC2YYBURZUVLR3URSBNXANCNFSM46NRGWGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.***>

It will be major change probably

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants