How to use the winston.format.timestamp function in winston

To help you get started, we’ve selected a few winston examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexilyaev / winston-format-pretty-console / src / index.spec.js View on Github external
it('should support format.timestamp()', () => {
      const info = {
        level: 'info',
        message: 'The quick brown fox jumps over the lazy dog'
      };
      const opts = {};
      const output = format
        .combine(format.timestamp(), prettyConsoleFormat())
        .transform({ ...info }, opts);

      expect(output).toMatchObject(info);
      expect(output).toHaveProperty('timestamp');
      expect(output[MESSAGE]).toMatch(output['timestamp']);
      // Timestamp is dynamic, removing it before matching
      expect(
        output[MESSAGE].replace(output['timestamp'], '')
      ).toMatchSnapshot();
    });
github neo-one-suite / neo-one / packages / neo-one-node-bin / src / utils / createMonitor.ts View on Github external
import { DefaultMonitor, LogLevel, Monitor } from '@neo-one/monitor';
import { createLogger, format, transports } from 'winston';

export interface MonitorEnvironment {
  readonly level: LogLevel;
}

const DEFAULT_FORMATS = format.combine(format.timestamp(), format.json());

export const createMonitor = ({ level }: MonitorEnvironment): Monitor => {
  const logger = createLogger({
    transports: [
      new transports.Console({
        level,
        format: DEFAULT_FORMATS,
      }),
    ],
  });

  logger.on('error', (error) => {
    // tslint:disable-next-line:no-console
    console.error(error);
  });
github hyperledger / caliper / packages / caliper-core / lib / common / utils / logging-util.js View on Github external
function _assembleDefaultFormat() {
    let formats = [];

    // add timestamp
    formats.push(format.timestamp({
        format: 'YYYY.MM.DD-HH:mm:ss.SSS'
    }));

    // pad level strings
    formats.push(PadLevelExtra());

    // enable aligning log messages
    formats.push(format.align());

    formats.push(AttributeFormat({
        level: ' %attribute%',
        label: ' [%attribute%]',
        module: ' [%attribute%] ',
        metadata: ' (%attribute%)'
    }));
github parse-community / parse-server / src / Adapters / Logger / WinstonLogger.js View on Github external
format.json()
              ),
            },
            options
          )
        );
        parseServer.name = 'parse-server';
        transports.push(parseServer);

        const parseServerError = new DailyRotateFile(
          Object.assign(
            {
              filename: 'parse-server.err',
              json: true,
              format: format.combine(
                format.timestamp(),
                format.splat(),
                format.json()
              ),
            },
            options,
            { level: 'error' }
          )
        );
        parseServerError.name = 'parse-server-error';
        transports.push(parseServerError);
      }
    } catch (e) {
      /* */
    }

    const consoleFormat = options.json ? format.json() : format.simple();
github viz-centric / flair-notifications / app / logger.js View on Github external
const { createLogger, format, transports } = require('winston');

const logger = createLogger({
  level: 'info',
  format: format.combine(
    format.timestamp({
      format: 'YYYY-MM-DD HH:mm:ss'
    }),
    format.errors({ stack: true }),
    format.splat(),
    format.json()
  ),
  defaultMeta: { service: 'notification-service' },
  transports: [
    //
    // - Write to all logs with level `info` and below to `combined.log`
    // - Write all logs error (and below) to `error.log`.
    //
    new transports.File({ filename: 'error.log', level: 'error' }),
    new transports.File({ filename: 'others.log' })
  ]
});
github WeebSearch / worker / typescript-worker / tools / logging.ts View on Github external
format.label({ label: "worker" }),
    format.timestamp({
      format: "HH-MM:ss YYYY-MM-DD"
    }),
  ),
  json: true,
  filename: "log/%DATE%.log",
  datePattern: "YYYY--MM-DD",
  zippedArchive: true,
  maxSize: "10m",
  maxFiles: "14d"
});

const logFormat = format.combine(
  format.label({ label: "worker" }),
  format.timestamp({
    format: 'HH-MM:ss YYYY-MM-DD'
  }),
  format.prettyPrint(),
  format.colorize(),
  format.align(),
  format.printf(info => {
    return `[${info.timestamp}] [${info.label}]@[${info.level}]: ${info.message}`;
  })
);

const consoleTransport = new transports.Console({
  format: logFormat,
  // level: process.env.LOG_LEVEL || "info"
  level: "info"
});
github ChainSafe / lodestar / packages / lodestar / src / logger / winston.ts View on Github external
public constructor(options?: Partial) {
    options = {
      level: LogLevel[defaultLogLevel],
      module: "",
      ...options,
    };
    this.winston = createLogger({
      level: LogLevel[LogLevel.verbose], // log level switching handled in `createLogEntry`
      defaultMeta: {
        module: options.module || "",
      },
      transports: [
        new transports.Console({
          format: format.combine(
            format.colorize(),
            format.timestamp({
              format: "YYYY-MM-DD HH:mm:ss"
            }),
            format.printf((info) => {
              const paddingBetweenInfo = 30;

              const infoString = (info.module || info.namespace || "");
              const infoPad = paddingBetweenInfo - infoString.length;

              return (
                `${info.timestamp}  [${infoString.toUpperCase()}] ${info.level.padStart(infoPad)}: ${info.message}`
              );
            })
          ),
          handleExceptions: true
        }),
      ],
github LISTEN-moe / discord-bot / src / util / logger.ts View on Github external
import { createLogger, transports, format } from 'winston';
import * as DailyRotateFile from 'winston-daily-rotate-file';

export const logger = createLogger({
	format: format.combine(
		format.errors({ stack: true }),
		format.label({ label: 'BOT' }),
		format.timestamp({ format: 'YYYY/MM/DD HH:mm:ss' }),
		format.printf((info: any): string => {
			const { timestamp, label, level, message, ...rest } = info;
			return `[${timestamp}][${label}][${level.toUpperCase()}]: ${message}${Object.keys(rest).length ? `\n${JSON.stringify(rest, null, 2)}` : ''}`;
		})
	),
	transports: [
		new transports.Console({
			format: format.colorize({ level: true }),
			level: 'info'
		}),
		new DailyRotateFile({
			format: format.combine(
				format.timestamp(),
				format.json()
			),
			level: 'debug',
github reactiflux / discord-irc / lib / logger.js View on Github external
);

  const padding = (info.padding && info.padding[info.level]) || '';
  if (stringifiedRest !== '{}') {
    return `${info.timestamp} ${info.level}:${padding} ${info.message} ${stringifiedRest}`;
  }

  return `${info.timestamp} ${info.level}:${padding} ${info.message}`;
}

const logger = winston.createLogger({
  transports: [new winston.transports.Console()],
  level: process.env.NODE_ENV === 'development' ? 'debug' : 'info',
  format: format.combine(
    format.colorize(),
    format.timestamp(),
    format.printf(formatter)
  )
});

export default logger;
github morko / haxroomie / packages / haxroomie-core / src / logger.js View on Github external
info: 2,
    verbose: 3,
    debug: 4,
  },
  colors: {
    error: 'red',
    warn: 'bold yellow',
    info: 'green',
    verbose: 'cyan',
    debug: 'grey',
  },
};

const alignedWithColorsAndTime = format.combine(
  format.colorize({ colors: customLevels.colors }),
  format.timestamp(),
  format.align(),
  format.printf(info => {
    const { timestamp, level, message, ...args } = info;
    const ts = timestamp.slice(0, 19).replace('T', ' ');
    return `${ts} [${level}] ${message.trim()} ${
      Object.keys(args).length ? stringify(args) : ''
    }`;
  })
);

const logger = createLogger({
  levels: customLevels.levels,
  format: alignedWithColorsAndTime,
});

let transportOptions;