Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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.
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"
'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/);
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`);
}
}
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;
"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;
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,
]
});
/**
* 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
),
),
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
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(