js-logger
js-logger copied to clipboard
Formatting example breaks console substition
formatter: function (messages, context) {
// prefix each log message with a timestamp.
messages.unshift(new Date().toUTCString());
},
});
will break: logger.log('Hello %s', 'Jonny')
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 https://github.com/jonnyreeves/js-logger/issues/106, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQ36LX7IZ2QM66YJ7GXHTTSBUWRANCNFSM46NRGWGA .
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
.
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.
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 https://github.com/jonnyreeves/js-logger/issues/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 https://github.com/jonnyreeves/js-logger/issues/106#issuecomment-997200131, 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: @.***>
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