How to use the winston.transports.Console 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 sandorTuranszky / production-ready-expressjs-server / src / utils / logger / winston.js View on Github external
};

/**
 * Instantiate a new Winston Logger with the settings defined above
 */
const logger = createLogger({
  format: combine(
    format.timestamp({
      format: 'YYYY-MM-DD hh:mm:ss',
    }),
    prettyPrint(),
  ),
  transports: [
    /* istanbul ignore next line */
    ...(config.app.logging.file ? [new transports.File(options.file)] : []),
    new transports.Console(options.console),
  ],
  exitOnError: false, // Do not exit on handled exceptions
});

/**
 * Create a 'stdout/stderr' stream object with a 'write' function that will be used by `morgan`
 */
logger.stream = {
  stdout: {
    // eslint-disable-next-line no-unused-vars
    write(message, encoding) {
      // Use the 'info' log level so the output will be picked up
      // By both transports (file and console)
      logger.info(message);
    },
  },
github qiufeihong2018 / navigation-server / services / logger.js View on Github external
printf
} = format;

require('winston-daily-rotate-file');
const config = require('../config')();
const MODE = require('../constant/system').MODE;
let mode = process.env.NODE_ENV;
if (!mode) mode = MODE.DEVE;

let logFile = config.logFile;

logFile = logFile.replace('.log', ''); // remove '.log' from the logFile

const trans = [];
const ts = {
  console: new transports.Console({
    level: 'debug'
  }),
  file: new transports.File({
    filename: `${logFile}.log`,
    level: 'info'
  })
};
// daily rotate file transport config
const dailyRotateFileTrans = new (transports.DailyRotateFile)({
  filename: `${logFile}-%DATE%.log`,
  datePattern: 'YYYY-MM-DD-HH',
  zippedArchive: true,
  maxSize: '20m',
  maxFiles: '7d'
});
// Dynamically change the log level of the transfer
github viz-centric / flair-notifications / app / logger.js View on Github external
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' })
  ]
});

//
// If we're not in production then **ALSO** log to the `console`
// with the colorized simple format.
//
logger.add(new transports.Console({
  format: format.combine(
    format.colorize(),
    format.simple()
  )
}));

module.exports=logger;
github goruck / smart-zoneminder / zm-s3-upload / logger.js View on Github external
new transports.File({
            filename: logConfig.baseName + 'combined.log',
            format: combine(
                timestamp(),
                json()
            ),
        })
    ]
});
          
//
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
// 
if (logConfig.consoleLog) {
    logger.add(new transports.Console ({
        format: simple()
    }));
}

module.exports = logger;
github zenprotocol / explorer / server / lib / namedLogger.js View on Github external
addedTransports.push(new transports.File({
      filename: path.join(logsDir, 'error.log'),
      level: 'error',
      maxsize: 5242880, // 5MB
      maxFiles: 5,
    }),
    new transports.File({
      filename: path.join(logsDir, 'combined.log'),
      maxsize: 5242880, // 5MB
      maxFiles: 5,
    }));
  }

  if (process.env.NODE_ENV !== 'test' || Config.get('SHOW_CONSOLE_LOGS')) {
    addedTransports.push(
      new transports.Console({
        format: combine(
          format.colorize(),
          label({ label: name }),
          format.timestamp(),
          format.printf(info => {
            return `[${colors.gray(info.label)}] ${info.timestamp} ${info.level}: ${info.message}`;
          })
        ),
      })
    );
  }

  const logger = createLogger({
    level: 'info',
    format: combine(label(), timestamp(), json()),
    transports: addedTransports,
github jauhararifin / ugrade / server-legacy / src / logger / logger.ts View on Github external
import { createLogger, format, transports } from 'winston'

export const options = {
  console: {
    level: 'debug',
    handleExceptions: true,
    json: false,
    colorize: true,
  },
}

export const logger = createLogger({
  format: format.combine(format.timestamp(), format.splat(), format.prettyPrint()),
  transports: [new transports.Console(options.console)],
  exitOnError: false,
})
github roboncode / orango / lib / Orango.js View on Github external
initLogger() {
    this.logger = createLogger({
      level: 'warn',
      format: format.combine(
        format.colorize({ message: false }),
        format.simple()
      ),
      transports: [new transports.Console()]
    })
  }
github node-ts / bus-starter / src / configuration / logger-configuration.ts View on Github external
import { injectable } from 'inversify'
import { WinstonConfiguration } from '@node-ts/logger-winston'
import { format, transports, LoggerOptions } from 'winston'

const consoleTransport = new transports.Console({
  handleExceptions: true
})

@injectable()
export class LoggerConfiguration implements WinstonConfiguration {

  /**
   * The "winston" logging library prefers a single instance of their logger
   * as creates an event emitter per instance. As such this function returns
   * a generic global configuration, with the metadata of the injection target
   * added via a logger proxy that's internal to `WinstonModule`
   */
  getConfiguration (): LoggerOptions {
    const devFormat = format.printf(({
      level,
      message,
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / config / logger.js View on Github external
const logger = createLogger({
    level: config.get('logLevel'),
    defaultMeta: { service: 'infrastructure-service' },
    transports: [
      new transports.Console({
        format: format.combine(
          format.json(),
          format.timestamp(),
        ),
      }),
    ],
  });

  if (process.env.NODE_ENV !== 'production') {
    logger.clear();
    logger.add(new transports.Console({
      format: format.combine(
        format.colorize(),
        format.splat(),
        format.simple(),
      ),
    }));
  }
  return logger;
}