winston#format TypeScript Examples

The following examples show how to use winston#format. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From serum-rest-server with Apache License 2.0 7 votes vote down vote up
logger = winston.createLogger({
  level: "silly",
  format: combine(timestamp(), logFormat),
  transports: [
    new winston.transports.Console({
      format: winston.format.simple(),
      level: "info",
    }),
  ],
})
Example #2
Source File: logger.utils.ts    From tradingview-alerts-processor with MIT License 7 votes vote down vote up
consoleLoggerOptions: transports.ConsoleTransportOptions = {
  level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
  format: combine(
    colorize(),
    timestamp({
      format: 'YYYY-MM-DD HH:mm:ss'
    }),
    format.printf(({ level, message, timestamp }) => {
      return `${timestamp}:${level}:${message}`;
    })
  )
}
Example #3
Source File: logger.ts    From graphql-schema-registry with MIT License 6 votes vote down vote up
function buildPrettyFormat() {
	return format.combine(
		format.colorize(),
		format.timestamp(),
		format.printf(({ timestamp, level, message }) => {
			return `[${timestamp}] ${level}: ${message}`;
		})
	);
}
Example #4
Source File: logger.ts    From projects-bot with MIT License 6 votes vote down vote up
export function init (): winston.Logger {
  const logPath = path.resolve(__dirname, '../../logs')

  const logger = createLogger({
    level: process.env.NODE_ENV !== 'development' ? 'info' : 'debug',
    format: format.json(),
    transports: [
      new transports.File({ filename: path.join(logPath, 'error.log'), level: 'error' }),
      new transports.File({ filename: path.join(logPath, 'full.log') }),
      new transports.Console({ format: format.combine(format.colorize(), format.simple()) })
    ]
  })

  return logger
}
Example #5
Source File: utils.ts    From serum-rest-server with Apache License 2.0 6 votes vote down vote up
{ combine, timestamp, printf } = format
Example #6
Source File: logger.ts    From TXQ with MIT License 6 votes vote down vote up
logger = createLogger({
  level: 'info',
  format: format.combine(
    format.timestamp({
      format: 'YYYY-MM-DD HH:mm:ss',
    }),
    format.errors({ stack: true }),
    format.splat(),
    format.json(),
  ),
  transports: transport,
  exitOnError: false,
})
Example #7
Source File: logger.ts    From bdk with Apache License 2.0 6 votes vote down vote up
defaultLoggerConfig = {
  level: config.isSillyMode ? 'silly' : 'debug',
  silent: config.isTestMode,
  format: format.combine(
    format.splat(),
    format.timestamp(),
    format.colorize(),
    format.printf(
      info => {
        if (info[LEVEL as any] === 'info') {
          return info.message.trim()
        } else {
          return `[bdk] ${info.timestamp} - ${info.level}: ${info.message}`
        }
      },
    ),
  ),
  transports: [new transports.Console({ stderrLevels: ['debug', 'warn', 'error'] })],
}
Example #8
Source File: logger.ts    From crypto-crawlers with Apache License 2.0 6 votes vote down vote up
export function createLogger(prefix: string): Logger {
  return createLoggerWinston({
    level: process.env.LOG_LEVEL || 'info',
    transports: [
      // see https://github.com/winstonjs/winston/issues/1217
      new transports.Console({
        format: format.combine(
          format.colorize(),
          format.prettyPrint(),
          format.splat(),
          format.simple(),
          format.printf((info) => {
            //  https://github.com/winstonjs/winston/issues/1498
            if (typeof info.message === 'object') {
              info.message = JSON.stringify(info.message, null, 2); // eslint-disable-line no-param-reassign
            }
            return `${info.level}: ${info.message}`;
          }),
        ),
      }),
      new transports.File({
        filename: `logs/${prefix}-${new Date().toISOString().substring(0, 10)}.log`,
      }),
    ],
  });
}
Example #9
Source File: application-container.ts    From ddd-cqrs-es-aws-sam with MIT License 6 votes vote down vote up
/**
   * Create logger
   * @returns Logger
   */
  private createLogger(): Logger {
    return createLogger({
      level: process.env.logLevel || 'debug',
      format: format.combine(
        format.prettyPrint(),
        format.splat(),
        format.simple(),
        format.timestamp(),
        format.printf(info => {
          if (info.message.constructor === Object) {
            info.message = JSON.stringify(info.message, null, 2)
          }

          return `${info.timestamp} ${info.level}: ${info.message}`
        }
      )),
      transports: [new transports.Console()]
    });
  }
Example #10
Source File: logger.ts    From gear-js with GNU General Public License v3.0 6 votes vote down vote up
Logger = (labelName: string) =>
  createLogger({
    level: 'debug',
    format: combine(
      format((info) => {
        info.level = info.level.toUpperCase();
        return info;
      })(),
      colorize(),
      label({ label: labelName }),
      timestamp({ format: 'DD/mm/YY HH:mm:ss' }),
      logFormat,
    ),
    transports: [new transports.Console()],
  })
Example #11
Source File: Logger.ts    From covid19-animation-generator with MIT License 6 votes vote down vote up
logger = createLogger({
	format: combine(
		colorize(),
		timestamp(),
		splat(),
		myFormat
	),
	transports: [new transports.Console()]
})
Example #12
Source File: DesktopAPI.ts    From rewind with MIT License 6 votes vote down vote up
function createLogger(logDirectory: string) {
  const fileFormat = format.combine(
    format.timestamp(),
    format.align(),
    format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`),
  );
  return WinstonModule.createLogger({
    level: "info",
    format: fileFormat,
    transports: [
      new winston.transports.File({ filename: join(logDirectory, "error.log"), level: "error" }),
      new winston.transports.File({ filename: join(logDirectory, "combined.log") }),
      new winston.transports.Console({
        format: format.combine(format.colorize(), fileFormat),
      }),
    ],
  });
}
Example #13
Source File: winston.ts    From eosio-contract-api with GNU Affero General Public License v3.0 6 votes vote down vote up
options = {
    exitOnError: false,
    level: defaultLevel,
    format: format.combine(
        format.metadata(),
        format.colorize(),
        format.timestamp(),
        format.printf((info: any) => {
            return `${info.timestamp} [PID:${process.pid}] [${info.level}] : ${info.message} ${Object.keys(info.metadata).length > 0 ? JSON.stringify(info.metadata) : ''}`;
        })
    )
}
Example #14
Source File: index.ts    From bedrock-cli with MIT License 6 votes vote down vote up
logger = createLogger({
  level: "info",
  format: format.combine(format.timestamp(), format.errors({ stack: true })),
  defaultMeta: { service: "bedrock" },
  transports: [
    new transports.File({
      filename: CLI_LOG_FILENAME,
      format: format.simple(),
    }),
    new transports.Console({
      format: format.cli(),
    }),
  ],
})
Example #15
Source File: logger.ts    From tezos-academy with MIT License 6 votes vote down vote up
logger = (): any => {
  winston.configure({
    level: process.env.NODE_ENV === DEVELOPMENT ? 'debug' : 'info',
    transports: [
      //
      // - Write all logs error (and below) to `error.log`.
      new transports.File({ filename: 'error.log', level: 'error' }),
      //
      // - Write to all logs with specified level to console.
      new transports.Console({
        format: format.combine(format.colorize(), format.simple()),
      }),
    ],
  })

  return async (ctx: Context, next: () => Promise<any>): Promise<void> => {
    const start = new Date().getTime()

    await next()

    const ms = new Date().getTime() - start

    let logLevel: string
    if (ctx.status >= 500) {
      logLevel = 'error'
    } else if (ctx.status >= 400) {
      logLevel = 'warn'
    } else {
      logLevel = 'info'
    }

    const msg = `${ctx.method} ${ctx.originalUrl} ${ctx.status} ${ms}ms`

    winston.log(logLevel, msg)
  }
}
Example #16
Source File: logger.ts    From server with MIT License 6 votes vote down vote up
logger = createLogger({
  level: 'error',
  format: format.combine(
    format.timestamp({
      format: 'YYYY-MM-DD HH:mm:ss'
    }),
    format.printf(data => `${data.timestamp}: ${data.message}`)
  ),
  transports: [new transports.File({ filename: 'logs/errors.log' })]
})
Example #17
Source File: logger.ts    From monkeytype with GNU General Public License v3.0 6 votes vote down vote up
coloredOutputFormat = format.printf((log) => {
  let color = infoColor;

  switch (log.level) {
    case "error":
      color = errorColor;
      break;
    case "warning":
      color = warningColor;
      break;
    case "success":
      color = successColor;
      break;
  }

  return `${log.timestamp}\t${color(log.message)}`;
})
Example #18
Source File: logger.ts    From antibody-web with MIT License 6 votes vote down vote up
logger : winston.Logger = winston.createLogger({ 
  transports: [
    new winston.transports.Console({ 
      format: format.combine(
        format.timestamp(),
        format.json(),
        format.colorize()
      ), 
      level: process.env.TEST ? 'silent' : "debug" 
    })
  ]
})
Example #19
Source File: logger.ts    From javascript-opensdk with Apache License 2.0 6 votes vote down vote up
customFormat = format.printf((msg) => {
  let fileMeta = '';

  // Extract the filename and line number from the stack trace
  strace.get().every((element) => {
    if (
      element.getFileName()?.includes('javascript-opensdk/dist/src') &&
      !element.getFileName()?.includes('logger.js')
    ) {
      const fileName = element.getFileName();
      fileMeta = `${fileName.substring(fileName.indexOf('javascript-opensdk'))}:${element.getLineNumber()}`;
      return false;
    }
    return true;
  });

  return `${msg.timestamp as string} [${msg.level}] (${fileMeta}): ${msg.message}`;
})
Example #20
Source File: logger.ts    From one-platform with MIT License 6 votes vote down vote up
winstonOptions: LoggerOptions = {
  transports: [
    new transports.Console(),
  ],
  format: format.combine(
    format.timestamp(),
    format.json(),
  ),
  silent: NODE_ENV === 'test',
}
Example #21
Source File: index.ts    From TidGi-Desktop with Mozilla Public License 2.0 6 votes vote down vote up
logger = (
  process.env.NODE_ENV === 'test'
    ? Object.assign(console, {
        emerg: console.error.bind(console),
        alert: console.error.bind(console),
        crit: console.error.bind(console),
        warning: console.warn.bind(console),
        notice: console.log.bind(console),
        debug: console.log.bind(console),
      })
    : winston.createLogger({
        levels,
        transports: [
          new winston.transports.Console(),
          new winston.transports.DailyRotateFile({
            filename: 'TidGi-%DATE%.log',
            datePattern: 'YYYY-MM-DD',
            zippedArchive: false,
            maxSize: '20mb',
            maxFiles: '14d',
            dirname: LOG_FOLDER,
            level: 'debug',
          }),
          new RendererTransport(),
        ],
        exceptionHandlers: [
          new winston.transports.DailyRotateFile({
            filename: 'TidGi-Exception-%DATE%.log',
            datePattern: 'YYYY-MM-DD',
            zippedArchive: false,
            maxSize: '20mb',
            maxFiles: '14d',
            dirname: LOG_FOLDER,
          }),
        ],
        format: format.combine(format.timestamp(), format.json()),
      })
) as winston.Logger
Example #22
Source File: logging.ts    From Assistive-Webdriver with MIT License 6 votes vote down vote up
export function createDefaultLogger(): Logger {
  return createLogger({
    format: format.combine(
      format.timestamp(),
      format.colorize(),
      messageId(),
      defaultFormatter
    ),
    transports: [new transports.Console()]
  });
}
Example #23
Source File: logger.utils.ts    From tradingview-alerts-processor with MIT License 6 votes vote down vote up
{ combine, json, timestamp, colorize } = format
Example #24
Source File: logger.ts    From javascript-opensdk with Apache License 2.0 6 votes vote down vote up
logger = createLogger({
  transports: [
    new transports.Console({
      level: 'warn',
      format: format.combine(
        format((info) => {
          const newInfo = info;
          newInfo.level = info.level.toUpperCase().padEnd(7, ' ');
          return newInfo;
        })(),
        format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
        format.colorize({ all: true }),
        customFormat
      ),
    }),
  ],
})
Example #25
Source File: Logger.ts    From ts-discord-bot-boilerplate with MIT License 6 votes vote down vote up
Logger = createLogger({
    transports: new Transports.Console(),
    format: combine(
        timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
        printf(({ message, level, timestamp }) =>
            colorizer.colorize(level, `[${timestamp}]: ${message}`)
        )
    )
})
Example #26
Source File: index.ts    From denote-md-backend with MIT License 6 votes vote down vote up
constructor(service: string, level: LogLevelType) {
    syslog.init(service);
    this.core = winston.createLogger({
      level,
      levels: winston.config.syslog.levels,
      format: combine(
        timestamp(),
        printf(
          (info: TransformableInfo) =>
            `${info.timestamp} ${info.service} ${colorByLevel(
              info.level,
              info.level,
            )} ${colorMessageByLevel(info.level, info.message)}`,
        ),
      ),
      defaultMeta: { service },
      transports: [new transports.Console(), new SyslogTransport({ syslog })],
    });
    this.level = LogLevel[level];
    this.debug('Start new winston instance', 'service');
  }
Example #27
Source File: logger.ts    From MyAPI with MIT License 6 votes vote down vote up
export function createLogger (): LoggerService {
  const winstonOptions : WinstonModuleOptions = {
    transports: [
      new transports.Console({
        format: format.combine(
          format.timestamp(),
          utilities.format.nestLike(),
        ),
        level: 'debug'
      }),
      new transports.File({
        format: format.combine(
          format.timestamp(),
          utilities.format.nestLike(),
        ),
        filename: 'errors.log',
        level: 'error'
      }),
      new transports.File({
        format: format.combine(
          format.timestamp(),
          utilities.format.nestLike(),
        ),
        filename: 'warnings.log',
        level: 'warning'
      }),
      new transports.File({
        format: format.combine(
          format.timestamp(),
          utilities.format.nestLike(),
        ),
        filename: 'critical.log',
        level: 'crit'
      })
    ]
  }

  return WinstonModule.createLogger(winstonOptions)
}
Example #28
Source File: winstonLoader.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
winstonLoader: MicroframeworkLoader = (settings: MicroframeworkSettings | undefined) => {
    configure({
        transports: [
            new transports.Console({
                level: env.log.level,
                handleExceptions: true,
                format: env.node !== 'development'
                    ? format.combine(
                        format.json()
                    )
                    : format.combine(
                        format.colorize(),
                        format.simple()
                    ),
            }),
        ],
    });
}
Example #29
Source File: endpointLogger.ts    From Nishan with MIT License 6 votes vote down vote up
endpointLogger = createLogger({
	level: 'info',
	format: combine(
		colorize(),
		timestamp({
			format: 'HH:mm:ss'
		}),
		printf(
			({ level, message, timestamp }) => `${colors.blue.bold(timestamp)} - ${level}: ${colors.bold.white(message)}`
		)
	),
	transports: [ new transports.Console() ]
})