How to use the winston.format.combine 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 mesaugat / express-api-es6-starter / src / utils / logger.js View on Github external
// Use LOG_DIR from env
const LOG_DIR = process.env.LOG_DIR || 'logs';
const LOG_LEVEL = process.env.LOG_LEVEL || 'info';

// Create log directory if it does not exist
if (!fs.existsSync(LOG_DIR)) {
  fs.mkdirSync(LOG_DIR);
}

/**
 * Create a new winston logger.
 */
const logger = winston.createLogger({
  transports: [
    new winston.transports.Console({
      format: format.combine(format.colorize(), format.simple()),
      level: 'info'
    }),
    new winston.transports.DailyRotateFile({
      format: format.combine(format.timestamp(), format.json()),
      maxFiles: '14d',
      level: LOG_LEVEL,
      dirname: LOG_DIR,
      datePattern: 'YYYY-MM-DD',
      filename: '%DATE%-debug.log'
    })
  ]
});

export const logStream = {
  /**
   * A writable stream for winston logger.
github WeebSearch / worker / typescript-worker / tools / logging.ts View on Github external
const fileTransport = new (transports.DailyRotateFile)({
  format: format.combine(
    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 alexilyaev / winston-format-pretty-console / src / example.js View on Github external
'use strict';

const { createLogger, format, transports } = require('winston');
const chalk = require('chalk');

const prettyConsoleFormat = require('./index');

const logger = createLogger({
  level: 'silly',
  format: format.combine(
    format.timestamp(),
    format.colorize(),
    prettyConsoleFormat()
  ),
  transports: [new transports.Console()]
});

// Basic
logger.info('The quick brown fox jumps over the lazy dog');
logger.info(chalk.dim('The quick brown fox jumps over the lazy dog'));
logger.info('The quick brown fox', chalk.dim('jumps over'), 'the lazy dog');
// Objects and other types
logger.info({ one: 1, two: 2, three: 3 });
logger.info(chalk.blue('[TEST]:'), { one: 1, two: 2 }, [3, 4, 5]);
logger.info(chalk.blue('[TEST]:'), null, undefined, 'one', 2, { 3: 3, 4: '4' });
logger.info(chalk.blue('[TEST]:'), chalk.yellow('Bombastic'), () => {}, /foo/);
github qdm12 / htmlspitter / src / logging.ts View on Github external
import { createLogger, format, transports, Logger } from "winston";

export let logger: Logger = createLogger({
    level: "info",
    format: format.combine(format.colorize(), format.cli()),
    transports: new transports.Console(),
});

export const setLoggerFormat = (s: string) => {
    switch (s) {
        case "json":
            logger.format = format.combine(format.json(), format.timestamp());
            break;
        case "normal":
            logger.format = format.combine(format.cli(), format.colorize());
            break;
        default:
            throw Error(`Logger format '${s}' is unrecognized`);
    }
}
github EspeoBlockchain / gardener-server / src / config / winston.js View on Github external
printFormat,
    ),
  },
  file: {
    filename: 'logs/combined.log',
    handleExceptions: true,
    format: format.combine(
      format.json(),
      printFormat,
    ),
  },
};

const logger = createLogger({
  level: env === 'development' ? 'debug' : 'info',
  format: format.combine(
    format.timestamp({
      format: 'YYYY-MM-DD HH:mm:ss',
    }),
    format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`),
  ),
  transports: [
    new transports.Console(options.console),
    new transports.File(options.file),
  ],
  exitOnError: false,
});

module.exports = logger;
github egovernments / egov-services / rainmaker / firenoc-calculator / src / config / logger.js View on Github external
"use strict";
import envVariables from "../envVariables";

const { createLogger, format, transports } = require("winston");

const logger = createLogger({
  level: envVariables.LOG_LEVEL,
  format: format.combine(
    format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSSZZ" }),
    format.json()
  ),
  transports: [new transports.Console()]
});

export default logger;
github parse-community / parse-server / src / Adapters / Logger / WinstonLogger.js View on Github external
function configureTransports(options) {
  const transports = [];
  if (options) {
    const silent = options.silent;
    delete options.silent;

    try {
      if (!_.isNil(options.dirname)) {
        const parseServer = new DailyRotateFile(
          Object.assign(
            {
              filename: 'parse-server.info',
              json: true,
              format: format.combine(
                format.timestamp(),
                format.splat(),
                format.json()
              ),
            },
            options
          )
        );
        parseServer.name = 'parse-server';
        transports.push(parseServer);

        const parseServerError = new DailyRotateFile(
          Object.assign(
            {
              filename: 'parse-server.err',
              json: true,
github hammer-io / tyr / src / utils / winston.js View on Github external
]
});

/**
 * The verbose logger
 */
loggers.add('verbose', {
  levels: customDebugLevels.levels,
  format: format.combine(
    format.colorize({ message: true }),
    customFormatting
  ),
  transports: [
    new transports.Console({
      level: 'verbose',
      format: format.combine(
        format.colorize({ message: true }),
        customFormatting
      ),
    })
  ]
});

/**
 * The debug logger
 */
loggers.add('debug', {
  levels: customDebugLevels.levels,
  format: format.combine(
    format.colorize({ message: true }),
    customFormatting
  ),
github TechAndCheck / tech-and-check-alerts / src / server / utils / logger.js View on Github external
),
  defaultMeta: { service: 'tech-and-check-alerts' },
  transports: [
    new transports.File({
      filename: 'logs/error.log',
      level: 'error',
    }),
    new transports.File({
      filename: 'logs/combined.log',
    }),
  ],
})

if (!isProductionEnv()) {
  logger.add(new transports.Console({
    format: format.combine(
      format.timestamp({
        format: 'HH:mm:ss',
      }),
      format.colorize(),
      format.timestamp(),
      format.align(),
      format.printf(info => `${info.timestamp} (${info.level}): ${info.message} ${info.stack || ''}`),
    ),
  }))
}

export default logger
github Aionic-Apps / aionic-core / src / config / logger.ts View on Github external
export const logger = createLogger({
	level: 'info',
	format: format.combine(
		format.timestamp({
			format: 'YYYY-MM-DD HH:mm:ss'
		}),
		format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)
	),
	transports: [
		new transports.File({
			filename: errorLog,
			level: 'error'
		}),
		new transports.File({
			filename: requestLog,
			format: format.combine(isRequest())
		}),
		new transports.File({
			filename: combinedLog
		})
	],
	exceptionHandlers: [
		new transports.File({
			filename: exceptionsLog
		})
	]
});

if (env.NODE_ENV !== 'production') {
	logger.add(
		new transports.Console({
			format: format.combine(