question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filename includes timezone offset. How to disable?

See original GitHub issue

I have faced with issue that the datePattern includes timezone offset. I would like to have the file names in UTC.

I’m using the next settings:

export interface IWinstonFactoryOptions {
  prefix?: string;
  console?: boolean;
  path: string;
  maxFiles: number;
}

function loggerFormat(data: TransformableInfo): string {
  return `${data.timestamp} [${data.label || ''}] ${data.level}: ${(data.durationMs !== undefined
    ? `(${data.durationMs}ms) `
    : '') + data.message}`;
}

export function createWinstonLogger(opts: IWinstonFactoryOptions): Logger {
  const prefix = opts.prefix || 'log_';
  const console = opts.console || false;

  const logger = createLogger({
    exitOnError: false,
    level: 'silly',
  });

  logger.add(
    new DailyRotateFile({
      format: format.combine(format.timestamp(), format.printf(loggerFormat)),
      filename: `${prefix}%DATE%.log`,
      datePattern: 'YYYY-MM-DDTHH',
      zippedArchive: false,
      maxFiles: opts.maxFiles,
      dirname: opts.path,
    })
  );

  if (console) {
    logger.add(
      new transports.Console({
        format: format.combine(format.colorize(), format.timestamp(), format.printf(loggerFormat)),
      })
    );
  }

  return logger;
}

Especially please look here: datePattern: 'YYYY-MM-DDTHH'

In practice I have the file: app_2019-07-24T22.log where the first line is: 2019-07-24T19:05:26.185Z [label] .... (I have +03 hours timezone)

Is that an issue or expected behaviour? I haven’t found way to force to use file rotator only UTC for file names.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mattberthercommented, Jul 29, 2019

This feature is being tracked at https://github.com/rogerc/file-stream-rotator/issues/31. Once this is supported by the file-stream-rotator component, I can publish a new version of winston to support the option.

1reaction
ifree92commented, Jul 30, 2019

@mattberther That would be great to have this option. I’m using Winston with application which is rotating on raspberry devices, and each has personal timezone and it’s a headache to have files not in UTC. If you can, please, publish new version with ability to use UTC for file names.

Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timezone offset in filenames without using + symbol? - Reddit
I personally use the "։" symbol (U+A789: MODIFIER LETTER COLON) in file names instead of a colon. It's just a Unicode character that...
Read more >
Having trouble setting a time zone offset during file renaming
I've solved it by looping through the folders on the card (100EOS5D, 101EOS5D, 102EOS5D, etc.), changing the filenames during the copy, and then ......
Read more >
Remove Time Zone Offset from DateTimeOffset?
My end goal is just to have a date without a time or a time zone offset. I do not want to convert...
Read more >
How to remove timezone information from DateTime object in ...
To remove timestamp, tzinfo has to be set None when calling replace() function. First, create a DateTime object with current time using datetime ......
Read more >
ZoneOffset (Java Platform SE 8 ) - Oracle Help Center
A time-zone offset from Greenwich/UTC, such as +02:00 . ... To prevent any problems with that range being extended, yet still provide validation,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found