Initial: Privacy Gateway Projekt mit Team-Implementierung
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import winston from 'winston';
|
||||
|
||||
const { combine, timestamp, json, printf, colorize, errors } = winston.format;
|
||||
|
||||
const devFormat = printf(({ level, message, timestamp, ...metadata }) => {
|
||||
let msg = `${timestamp} [${level}]: ${message}`;
|
||||
if (Object.keys(metadata).length > 0) {
|
||||
msg += ` ${JSON.stringify(metadata)}`;
|
||||
}
|
||||
return msg;
|
||||
});
|
||||
|
||||
export const createLogger = (service: string): winston.Logger => {
|
||||
const isDev = process.env.NODE_ENV !== 'production';
|
||||
const logLevel = process.env.LOG_LEVEL || (isDev ? 'debug' : 'info');
|
||||
|
||||
return winston.createLogger({
|
||||
level: logLevel,
|
||||
defaultMeta: { service },
|
||||
format: isDev
|
||||
? combine(
|
||||
colorize(),
|
||||
timestamp({ format: 'HH:mm:ss' }),
|
||||
errors({ stack: true }),
|
||||
devFormat
|
||||
)
|
||||
: combine(
|
||||
timestamp(),
|
||||
json()
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
stderrLevels: ['error'],
|
||||
}),
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
export const logger = createLogger('App');
|
||||
Reference in New Issue
Block a user