Skip to content

Commit

Permalink
Log in local timezone. #2341
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Nov 15, 2019
1 parent 31246ef commit 44db557
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/util/logger.js
Expand Up @@ -24,6 +24,8 @@ const levelWithCompensatedLength = {
'debug': 'debug',
};

const timestampFormat = () => moment().format('YYYY-MM-DD HH:mm:ss');

// Create logger
const transports = {
file: new winston.transports.File({
Expand All @@ -33,7 +35,7 @@ const transports = {
maxFiles: 3, // Keep last 3 files
maxsize: 10000000, // 10MB
format: winston.format.combine(
winston.format.timestamp(),
winston.format.timestamp({format: timestampFormat}),
winston.format.printf(/* istanbul ignore next */(info) => {
const {timestamp, level, message} = info;
return `${levelWithCompensatedLength[level]} ${timestamp.split('.')[0]}: ${message}`;
Expand All @@ -43,7 +45,7 @@ const transports = {
console: new winston.transports.Console({
level,
format: winston.format.combine(
winston.format.timestamp(),
winston.format.timestamp({format: timestampFormat}),
winston.format.printf(/* istanbul ignore next */(info) => {
const {timestamp, level, message} = info;
const prefix = colorizer.colorize(level, `zigbee2mqtt:${levelWithCompensatedLength[level]}`);
Expand Down

3 comments on commit 44db557

@Kryzek
Copy link
Contributor

@Kryzek Kryzek commented on 44db557 Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: could timestampFormat be something one could set up also in configuration.yaml?

@Koenkk
Copy link
Owner Author

@Koenkk Koenkk commented on 44db557 Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, feel free to make a pr.

@Kryzek
Copy link
Contributor

@Kryzek Kryzek commented on 44db557 Nov 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dear. I usually just read code and do some cut and paste-coding. But it could be a good learning experience. I will give it a shot at some point.

Please sign in to comment.