winston#transports TypeScript Examples
The following examples show how to use
winston#transports.
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: logger.utils.ts From tradingview-alerts-processor with MIT License | 7 votes |
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 #2
Source File: util.ts From bedrock-cli with MIT License | 7 votes |
turnOffConsoleLogging = (logger: Logger): void => {
//If logging level is not verbose
if (logger.level !== "silly") {
logger.transports.forEach((t) => {
if (t instanceof transports.Console) {
t.silent = true;
}
});
}
}
Example #3
Source File: logger.ts From Deep-Lynx with MIT License | 6 votes |
private constructor() {
this.logger = winston.createLogger({
level: Config.log_level,
silent: Config.log_level === 'silent',
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.printf(({level, message, label, timestamp}) => {
return `${timestamp} ${level}: ${message}`;
}),
),
}),
new winston.transports.File({
filename: 'combined.log',
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.printf(({level, message, label, timestamp}) => {
return `${timestamp} ${level}: ${message}`;
}),
),
}),
],
exceptionHandlers: [
new transports.File({filename: 'exceptions.log'}),
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.printf(({level, message, label, timestamp}) => {
return `${timestamp} ${level}: ${message}`;
}),
),
}),
],
});
}
Example #4
Source File: logger.ts From javascript-opensdk with Apache License 2.0 | 6 votes |
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 #5
Source File: logger.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 6 votes |
configureLogger = () => {
configure({
transports: [
new transports.Console({
level: 'none',
handleExceptions: false,
}),
],
});
}
Example #6
Source File: winstonLoader.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #7
Source File: logger-console.ts From loopback4-microservice-catalog with MIT License | 6 votes |
constructor() {
super();
const logFormat = format.combine(
format.uncolorize(),
format.timestamp(),
format.printf(
(log: LogEntry) => `[${log.timestamp}] ${log.level} :: ${log.message}`,
),
);
this.logger = createLogger({
transports: [new transports.Console()],
format: logFormat,
level:
process.env.LOG_LEVEL ??
LOGGER.LOG_LEVEL[LOGGER.LOG_LEVEL.ERROR].toLowerCase(),
});
}
Example #8
Source File: logger.ts From MyAPI with MIT License | 6 votes |
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 #9
Source File: logger.ts From tezos-academy with MIT License | 6 votes |
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 #10
Source File: logger.ts From server with MIT License | 6 votes |
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 #11
Source File: index.ts From bedrock-cli with MIT License | 6 votes |
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 #12
Source File: util.ts From bedrock-cli with MIT License | 6 votes |
turnOnConsoleLogging = (logger: Logger): void => {
logger.transports.forEach((t) => {
if (t instanceof transports.Console) {
t.silent = false;
}
});
}
Example #13
Source File: commandBuilder.ts From bedrock-cli with MIT License | 6 votes |
exit = (
log: Logger,
exitFn: (status: number) => void,
statusCode: number,
timeout = 10000
): Promise<void> => {
return new Promise((resolve) => {
const hasFileLogger = log.transports.some((t) => {
if (t instanceof transports.File) {
// callback will be called once if bedrock.log
// already exist.
// it will be called twice if bedrock.log
// do not exist. the one call has size === 0
fs.watchFile(t.filename, (curr) => {
if (curr.size > 0) {
exitFn(statusCode);
resolve();
}
});
return true;
}
return false;
});
// file logger may be not added to logger.
// then we end the command.
if (!hasFileLogger) {
exitFn(statusCode);
resolve();
} else {
// this is to handle the case when nothing to be written to bedrock.log
// handle fs.watchFile callback will not be execute.
setTimeout(() => {
exitFn(statusCode);
resolve();
}, timeout); // 10 seconds should be enough
}
});
}
Example #14
Source File: logger.utils.ts From tradingview-alerts-processor with MIT License | 6 votes |
errorLogFileLoggerOptions: transports.FileTransportOptions = {
filename: 'logs/error.log',
level: 'error'
}
Example #15
Source File: Logger.ts From covid19-animation-generator with MIT License | 6 votes |
logger = createLogger({
format: combine(
colorize(),
timestamp(),
splat(),
myFormat
),
transports: [new transports.Console()]
})
Example #16
Source File: logger.ts From gear-js with GNU General Public License v3.0 | 6 votes |
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 #17
Source File: methodLogger.ts From Nishan with MIT License | 6 votes |
methodLogger = 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() ]
})
Example #18
Source File: logger.ts From one-platform with MIT License | 6 votes |
winstonOptions: LoggerOptions = {
transports: [
new transports.Console(),
],
format: format.combine(
format.timestamp(),
format.json(),
),
silent: NODE_ENV === 'test',
}
Example #19
Source File: Logging.ts From vircadia-metaverse with Apache License 2.0 | 6 votes |
Logger : ALogger = {
info: (msg: string) => {
logger.log('info', msg);
},
warn: (msg: string) => {
logger.log('warn', msg);
},
debug: (msg: string) => {
logger.log('debug', msg);
},
// Conditional debug. Looks for "debug.flag" in configuration.
cdebug: (flag: string, msg: string) => {
if ((Config.debug as any)[flag]) {
logger.log('debug', msg);
};
},
error: (msg: string) => {
logger.log('error', msg);
},
setLogLevel: ( level: string) => {
if (level) {
const aLevel = level.toLowerCase();
if ([ 'info', 'warn', 'debug', 'error'].includes(aLevel)) {
transports.File.level = aLevel;
transports.Console.level = aLevel;
}
else {
Logger.error(`Logger.setLogLevel: unknown level name: ${level}`);
Logger.setLogLevel('info');
};
}
else {
Logger.error(`Logger.setLogLevel: false level name: ${level}`);
transports.File.level = 'debug';
};
}
}
Example #20
Source File: logging.ts From Assistive-Webdriver with MIT License | 6 votes |
export function createDefaultLogger(): Logger {
return createLogger({
format: format.combine(
format.timestamp(),
format.colorize(),
messageId(),
defaultFormatter
),
transports: [new transports.Console()]
});
}
Example #21
Source File: Logging.ts From vircadia-metaverse with Apache License 2.0 | 6 votes |
logger = winston.createLogger( {
'level': 'debug',
'format': winston.format.combine(
winston.format.timestamp(),
winston.format.printf(info => { return `${info.timestamp} ${info.level} ${info.message}` })
),
'transports': [
new winston.transports.Console( {
'level': 'debug'
})
]
})
Example #22
Source File: index.ts From denote-md-backend with MIT License | 6 votes |
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 #23
Source File: endpointLogger.ts From Nishan with MIT License | 6 votes |
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() ]
})
Example #24
Source File: application-container.ts From ddd-cqrs-es-aws-sam with MIT License | 6 votes |
/**
* 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 #25
Source File: Logger.ts From jaebook-server with MIT License | 6 votes |
options: LoggerOptions = {
level,
exitOnError: false,
format: combine(
timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
errors({ stack: true }),
),
transports: [
// 콘솔 로그 출력
new transports.Console({
handleExceptions: true,
format: consoleOutputFormat,
}),
// 파일 로그 출력
new DailyRotateFile({
handleExceptions: true,
format: fileOutputFormat,
filename,
}),
],
}
Example #26
Source File: logger.ts From projects-bot with MIT License | 6 votes |
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 #27
Source File: logger.utils.ts From tradingview-alerts-processor with MIT License | 6 votes |
tradesLogFileLoggerOptions: transports.FileTransportOptions = {
filename: 'logs/trades.log'
}
Example #28
Source File: logger.ts From TXQ with MIT License | 6 votes |
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 #29
Source File: logger.utils.ts From tradingview-alerts-processor with MIT License | 6 votes |
debugLogFileLoggerOptions: transports.FileTransportOptions = {
filename: 'logs/debug.log'
}