add logger

This commit is contained in:
Francesco Esposito 2019-08-15 23:21:42 +02:00
parent 5c492c59e1
commit 077ebbb278
1 changed files with 27 additions and 0 deletions

27
src/logger.js Normal file
View File

@ -0,0 +1,27 @@
import winston from 'winston';
const { format } = winston;
const customFormat = format.printf(({
level,
message,
label,
timestamp,
}) => `${timestamp} [${label}] ${level}: ${message}`);
const logger = winston.createLogger({
level: 'info',
format: format.combine(
format.label({ label: 'umbrello-api' }),
format.timestamp(),
customFormat,
),
defaultMeta: { service: 'user-service' },
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' }),
],
});
export default logger;