@daiyu-5577/quickbuild
Version:
front-end build service
69 lines (68 loc) • 2.31 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import winston, { format } from 'winston';
import path from 'path';
import dayjs from 'dayjs';
import { catchHttpLogPath } from '../command/config.js';
import 'winston-daily-rotate-file';
const { combine, timestamp, label, printf, prettyPrint, json, align } = format;
const __dirname = new URL('.', import.meta.url).pathname;
const customLevels = {
levels: {
error: 0,
warn: 1,
info: 2,
socket: 3,
http: 4,
},
colors: {
error: 'red',
warn: 'yellow',
info: 'blue',
socket: 'green',
http: 'green',
}
};
const custFormat = (opt) => printf((params) => {
const { timestamp, label, level, message } = params, arg = __rest(params, ["timestamp", "label", "level", "message"]);
const str = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [${label}] [${level}] ${message} ${JSON.stringify(arg, null, 2)}`;
return str;
});
const logger = winston.createLogger({
level: 'http',
levels: customLevels.levels,
defaultMeta: {},
format: combine(timestamp(), label({
label: 'quickBuild'
}), custFormat()),
transports: [
new winston.transports.DailyRotateFile({
level: 'http',
filename: path.resolve(catchHttpLogPath, '%DATE%_http.log'),
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
}),
new winston.transports.DailyRotateFile({
level: 'socket',
filename: path.resolve(catchHttpLogPath, '%DATE%_socket.log'),
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
}),
],
exitOnError: false,
});
winston.addColors(customLevels.colors);
export default logger;