Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
level: logLevel,
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
format.splat()
),
defaultMeta: { service: 'ripple-tide' },
transports: [
new transports.Console({
format: format.combine(
format(info => {
info.level = ` ${info.level.toUpperCase()} `
return info
})(),
format.colorize(),
printFormat
)
})
]
})
if (!process.client) {
// TODO: We may not need to log to ES for pr branch.
if (process.env.LAGOON_GIT_SAFE_BRANCH) {
logger.add(new LogstashTransport({
host: 'application-logs.lagoon.svc',
port: 5140,
handleExceptions: true,
format: format.combine(
lagoonFormat(),
errorPrint(),
const { Level, env } = require('./env-vars');
// { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
const formatParams = (info) => {
const {
timestamp, level, message, ...args
} = info;
const ts = timestamp.slice(0, 19).replace('T', ' ');
return `${ts} ${level}: ${message} ${Object.keys(args).length
? JSON.stringify(args, '', '')
: ''}`;
};
const Format = format.combine(
format.colorize(),
format.timestamp(),
format.align(),
format.printf(formatParams),
);
const transportArray = (
env === 'production'
? [new transports.File({ filename: 'error.log', level: 'error' })]
: [new transports.Console()]
);
const logger = createLogger({
Level,
format: Format,
transports: transportArray,
});
let log = null;
let timeZone = null;
// add the timestamp in the correct format to the log info object
const timestampFormat = format.timestamp({
format () {
let date = new Date();
if (!timeZone) {
date = new Date(date.valueOf() + date.getTimezoneOffset() * 60000);
}
return dateformat(date, 'yyyy-mm-dd HH:MM:ss:l');
},
});
// set the custom colors
const colorizeFormat = format.colorize({
colors,
});
// Strip the color marking within messages
const stripColorFormat = format(function stripColor (info) {
const code = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex
info.message = info.message.replace(code, '');
return info;
})();
function createConsoleTransport (args, logLvl) {
return new (transports.Console)({
name: 'console',
handleExceptions: true,
exitOnError: false,
json: false,
_initCommon(name) {
this._commonLogger = createLogger({
format: format.combine(
format.errors({ stack: false }),
format.simple(),
format.colorize()
),
transports: [
new transports.File({ filename: path.join(logPath, `${name}_${this.date}.log`), level: "info" }),
new transports.File({ filename: path.join(logPath, `${name}_error_${this.date}.log`), level: "error" }),
new transports.File({ filename: path.join(logPath, "debug.log"), level: "debug", maxsize: 1024 * 1024 * 10 })
]
});
if (process.env.NODE_ENV !== "formal") {
this._commonLogger.add(new transports.Console({
format: format.combine(
format.errors({ stack: false }),
format.simple()
),
}));
}
}
import { createLogger, format, transports } from 'winston'
export default createLogger({
format: format.combine(
format.prettyPrint(),
format.colorize(),
format.simple()
),
transports: [new transports.Console()]
})
"use strict";
//Sets up a reusable winston logger for the rest of the application. It reads the log level from the environmental variable LOG_LEVEL.
const { createLogger, format, transports } = require("winston");
var logLevel = 'error';
if (process.env.LOG_LEVEL === 'development'){
var logLevel = 'debug';
}
const level = logLevel;
const logger = createLogger({
format: format.combine(
format.timestamp(),
format.colorize(),
format.printf(info => `[${info.timestamp}] ${info.level}: ${info.message}`)
),
transports: [
new transports.Console({
level: level,
timestamp: function () {
return (new Date()).toISOString();
}
}),
new transports.File({
filename: '/usr/src/app/private/logs/errors.log',
maxsize: 10000,
maxFiles: 2,
level: 'error'
}),
new transports.File({
new transports.File({
filename: combinedLog
})
],
exceptionHandlers: [
new transports.File({
filename: exceptionsLog
})
]
});
if (env.NODE_ENV !== 'production') {
logger.add(
new transports.Console({
format: format.combine(
format.colorize(),
format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)
),
level: 'debug'
})
);
}
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
import util from "util";
import { Logger, LoggerProps } from "./logger";
export type WinstonLoggerOptions = Winston.LoggerOptions;
export class WinstonLogger extends Logger {
public static readonly key = "winston";
private static readonly defaultOptions: WinstonLoggerOptions = {
level: "info",
silent: false,
transports: [
new transports.Console({
format: format.combine(
format.timestamp(),
format.prettyPrint(),
format.colorize(),
format.printf(({level, message, timestamp, label}) => {
return `${timestamp} ${level} ${kleur.yellow(label)}: ${message}`;
}),
),
}),
],
};
private static printObject = (o: any): string => util.inspect(o, {showHidden: false, depth: 3, colors: true});
private readonly logger: Winston.Logger;
protected readonly opts: Winston.LoggerOptions;
constructor(protected readonly props: LoggerProps, opts?: WinstonLoggerOptions, reusableLogger?: Winston.Logger) {
super(props);
this.opts = _.defaults(opts || {}, WinstonLogger.defaultOptions);
this.logger = reusableLogger || Winston.createLogger(this.opts);
const { createLogger, format, transports } = require('winston')
require('winston-daily-rotate-file')
const config = require('config')
const level = config.get('logs.level')
module.exports = createLogger({
level,
format: format.combine(
format.simple(),
format.colorize(),
format.timestamp(),
format.printf(info => `[${info.timestamp}] ${info.level} ${info.message}`)
),
transports: [
new transports.DailyRotateFile({
datePattern: 'YYYY-MM-DD',
filename: `${process.cwd()}/logs/%DATE%.log`,
maxSize: '20m',
maxFiles: '7d',
format: format.uncolorize()
}),
new transports.Console({
level
})
]
})