bluelinky2
Version:
An unofficial nodejs API wrapper for Hyundai bluelink
35 lines (28 loc) • 803 B
text/typescript
import * as winston from 'winston';
const defaultLevel = process.env.LOG_LEVEL || 'info';
const { colorize, combine, timestamp, printf } = winston.format;
interface LogInfo extends winston.Logform.TransformableInfo {
timestamp?: string;
}
const myFormat = printf((info: LogInfo) => {
// convert objects into strings
if (typeof info.message === 'object') {
info.message = JSON.stringify(info.message, null, 2);
}
return `[${info.timestamp}] ${info.level}: ${info.message}`;
});
const combinedFormats = combine(
timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
colorize(),
myFormat,
);
const logger: winston.Logger = winston.createLogger({
format: combinedFormats,
level: defaultLevel,
transports: [
new winston.transports.Console(),
],
});
export default logger;