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

Filename includes timezone offset. How to disable? #231

Closed
ifree92 opened this issue Jul 24, 2019 · 6 comments
Closed

Filename includes timezone offset. How to disable? #231

ifree92 opened this issue Jul 24, 2019 · 6 comments

Comments

@ifree92
Copy link
Contributor

ifree92 commented Jul 24, 2019

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.

@mattberther
Copy link
Member

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

@ifree92
Copy link
Contributor Author

ifree92 commented 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

@mscottnelson
Copy link

mscottnelson commented Sep 3, 2019

@mattberther, file-stream-rotator has published an update enabling a UTC option as of 0.5.0. Additionally, a bug fix related to varying results depending on when file-stream-rotator evaluated has been fixed: rogerc/file-stream-rotator#53

So, a UTC option should now be possible. Let me know if you would like a PR.

@mattberther
Copy link
Member

mattberther commented Sep 3, 2019

Thanks for the offer, @mscottnelson. If you have a PR, I'd welcome it. If not, I should be able to incorporate this in the next day or two. :)

@IvayloB9
Copy link

IvayloB9 commented Sep 5, 2019

Thank you for the quick turnaround! :)

@ifree92
Copy link
Contributor Author

ifree92 commented Sep 6, 2019

Just added PR for utc option on d.ts.
Would be great to have a new release asap :)

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

4 participants