Better Logging
  • Introduction
  • Setup
    • Install
    • Log Levels
  • Configuration
    • format
    • formatStamp
    • saveToFile
    • logLevels
    • color
    • messageConstructionStrategy
  • extra
    • Decorate Arbitrary Object
    • Custom Instance
    • Express Middleware
    • Typescript Support
  • Upgrade Guides
    • 4.x to 5.x
    • 3.x to 4.x
Powered by GitBook
On this page

Was this helpful?

  1. Upgrade Guides

4.x to 5.x

PreviousTypescript SupportNext3.x to 4.x

Last updated 2 years ago

Was this helpful?

Message formatting

With version 5.x better-logging now adheres to the standard for dates and time stamps. This brings with it some changes to the message formatting context object.

  • The string format of ctx.date has changed from DD/MM/YYYY to YYYY-MM-DD.

  • The introduction of a unified ctx.time has rendered ctx.time12 and ctx.time24 redundant, and they have there for been removed. The string format of the new unified ctx.time is as follows hh:mm:ss.mmm where the additional mmm at the end stands for milliseconds.

// IN 4.x
betterLogging(console, {
  format: (ctx) => `${ctx.date} ${ctx.time24} ${ctx.msg}`,
});
console.log('Hi'); // [25/05/2022] [20:54:58] Hi

// IN 5.x
betterLogging(console, {
  format: (ctx) => `${ctx.date} ${ctx.time} ${ctx.msg}`,
});
console.log('Hi'); // [2022-05-25] [20:54:58.298] Hi
ISO8601