@strapi/logger
Advanced tools
Comparing version 0.0.0-next.39bf1ab0d2e327b0a192d2f5adcb4182de865411 to 0.0.0-next.39c0188c3aa01bec7b64b948211571d5159e811d
@@ -1,17 +0,17 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
const winston = require("winston"); | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); | ||
'use strict'; | ||
var winston = require('winston'); | ||
function _interopNamespaceDefault(e) { | ||
var n = Object.create(null); | ||
if (e) { | ||
for (const k in e) { | ||
if (k !== "default") { | ||
const d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: () => e[k] | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -21,100 +21,116 @@ n.default = e; | ||
} | ||
const winston__namespace = /* @__PURE__ */ _interopNamespace(winston); | ||
var winston__namespace = /*#__PURE__*/_interopNamespaceDefault(winston); | ||
const LEVELS = winston.config.npm.levels; | ||
const LEVEL_LABEL = "silly"; | ||
const LEVEL_LABEL = 'silly'; | ||
LEVELS[LEVEL_LABEL]; | ||
const logErrors = winston.format((info) => { | ||
if (info instanceof Error) { | ||
return { ...info, message: `${info.message}${info.stack ? ` | ||
${info.stack}` : ""}` }; | ||
} | ||
return info; | ||
const logErrors = winston.format((info)=>{ | ||
if (info instanceof Error) { | ||
return { | ||
...info, | ||
message: `${info.message}${info.stack ? `\n${info.stack}` : ''}` | ||
}; | ||
} | ||
return info; | ||
}); | ||
const defaultTimestampFormat = "YYYY-MM-DD HH:mm:ss.SSS"; | ||
const prettyPrint = (options = {}) => { | ||
const { timestamps = true, colors = true } = options; | ||
const handlers = []; | ||
if (timestamps) { | ||
handlers.push( | ||
winston.format.timestamp({ | ||
format: timestamps === true ? defaultTimestampFormat : timestamps | ||
}) | ||
); | ||
} | ||
if (colors) { | ||
handlers.push(winston.format.colorize()); | ||
} | ||
handlers.push(logErrors()); | ||
handlers.push( | ||
winston.format.printf(({ level, message, timestamp }) => { | ||
return `${timestamps ? `[${timestamp}] ` : ""}${level}: ${message}`; | ||
}) | ||
); | ||
return winston.format.combine(...handlers); | ||
}; | ||
const levelFilter = (...levels) => { | ||
return winston.format((info) => levels.some((level) => info.level.includes(level)) ? info : false)(); | ||
}; | ||
const excludeColors = winston.format.printf(({ message }) => { | ||
if (typeof message !== "string") { | ||
return message; | ||
} | ||
return message.replace( | ||
// eslint-disable-next-line no-control-regex | ||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, | ||
"" | ||
); | ||
const defaultTimestampFormat = 'YYYY-MM-DD HH:mm:ss.SSS'; | ||
/** | ||
* Create a pretty print formatter for a winston logger | ||
* @param options | ||
*/ var prettyPrint = ((options = {})=>{ | ||
const { timestamps = true, colors = true } = options; | ||
const handlers = []; | ||
if (timestamps) { | ||
handlers.push(winston.format.timestamp({ | ||
format: timestamps === true ? defaultTimestampFormat : timestamps | ||
})); | ||
} | ||
if (colors) { | ||
handlers.push(winston.format.colorize()); | ||
} | ||
handlers.push(logErrors()); | ||
handlers.push(winston.format.printf(({ level, message, timestamp })=>{ | ||
return `${timestamps ? `[${timestamp}] ` : ''}${level}: ${message}`; | ||
})); | ||
return winston.format.combine(...handlers); | ||
}); | ||
const detailedLog = winston.format.printf(({ message, level, timestamp }) => { | ||
if (typeof message !== "string") { | ||
return message; | ||
} | ||
const newMessage = `[${timestamp}] ${level}: ${message}`; | ||
return newMessage.replace( | ||
// eslint-disable-next-line no-control-regex | ||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, | ||
"" | ||
); | ||
var levelFilter = ((...levels)=>{ | ||
return winston.format((info)=>levels.some((level)=>info.level.includes(level)) ? info : false)(); | ||
}); | ||
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
/** | ||
* This will remove the chalk color codes from the message provided. | ||
* It's used to log plain text in the log file | ||
*/ var excludeColors = winston.format.printf(({ message })=>{ | ||
if (typeof message !== 'string') { | ||
return message; | ||
} | ||
return message.replace(// eslint-disable-next-line no-control-regex | ||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); | ||
}); | ||
/** | ||
* This will remove the chalk color codes from the message provided. | ||
* It's used to log plain text in the log file | ||
*/ var detailedLog = winston.format.printf(({ message, level, timestamp })=>{ | ||
if (typeof message !== 'string') { | ||
return message; | ||
} | ||
const newMessage = `[${timestamp}] ${level}: ${message}`; | ||
return newMessage.replace(// eslint-disable-next-line no-control-regex | ||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); | ||
}); | ||
var index$1 = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
detailedLogs: detailedLog, | ||
excludeColors, | ||
levelFilter, | ||
prettyPrint | ||
}, Symbol.toStringTag, { value: "Module" })); | ||
const defaultConfiguration = () => { | ||
return { | ||
level: LEVEL_LABEL, | ||
levels: LEVELS, | ||
format: prettyPrint(), | ||
transports: [new winston.transports.Console()] | ||
}; | ||
}; | ||
const outputFileConfiguration = (filename, fileTransportOptions = {}) => { | ||
return { | ||
level: LEVEL_LABEL, | ||
levels: LEVELS, | ||
format: prettyPrint(), | ||
transports: [ | ||
new winston.transports.Console(), | ||
new winston.transports.File({ | ||
level: "error", | ||
filename, | ||
format: excludeColors, | ||
...fileTransportOptions | ||
}) | ||
] | ||
}; | ||
}; | ||
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
excludeColors: excludeColors, | ||
levelFilter: levelFilter, | ||
prettyPrint: prettyPrint | ||
}); | ||
var defaultConfiguration = (()=>{ | ||
return { | ||
level: LEVEL_LABEL, | ||
levels: LEVELS, | ||
format: prettyPrint(), | ||
transports: [ | ||
new winston.transports.Console() | ||
] | ||
}; | ||
}); | ||
var outputFileConfiguration = ((filename, fileTransportOptions = {})=>{ | ||
return { | ||
level: LEVEL_LABEL, | ||
levels: LEVELS, | ||
format: prettyPrint(), | ||
transports: [ | ||
new winston.transports.Console(), | ||
new winston.transports.File({ | ||
level: 'error', | ||
filename, | ||
format: excludeColors, | ||
...fileTransportOptions | ||
}) | ||
] | ||
}; | ||
}); | ||
var index = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
createDefaultConfiguration: defaultConfiguration, | ||
createOutputFileConfiguration: outputFileConfiguration | ||
}, Symbol.toStringTag, { value: "Module" })); | ||
const createLogger = (userConfiguration = {}) => { | ||
const configuration = defaultConfiguration(); | ||
Object.assign(configuration, userConfiguration); | ||
return winston__namespace.createLogger(configuration); | ||
}); | ||
const createLogger = (userConfiguration = {})=>{ | ||
const configuration = defaultConfiguration(); | ||
Object.assign(configuration, userConfiguration); | ||
return winston__namespace.createLogger(configuration); | ||
}; | ||
exports.winston = winston__namespace; | ||
@@ -121,0 +137,0 @@ exports.configs = index; |
{ | ||
"name": "@strapi/logger", | ||
"version": "0.0.0-next.39bf1ab0d2e327b0a192d2f5adcb4182de865411", | ||
"version": "0.0.0-next.39c0188c3aa01bec7b64b948211571d5159e811d", | ||
"description": "Strapi's logger", | ||
@@ -34,7 +34,9 @@ "homepage": "https://strapi.io", | ||
"scripts": { | ||
"build": "pack-up build", | ||
"build": "run -T npm-run-all clean --parallel build:code build:types", | ||
"build:code": "run -T rollup -c", | ||
"build:types": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly", | ||
"clean": "run -T rimraf ./dist", | ||
"lint": "run -T eslint .", | ||
"test:ts": "run -T tsc --noEmit", | ||
"watch": "pack-up watch" | ||
"watch": "run -T rollup -c -w" | ||
}, | ||
@@ -46,5 +48,4 @@ "dependencies": { | ||
"devDependencies": { | ||
"@strapi/pack-up": "5.0.2", | ||
"eslint-config-custom": "0.0.0-next.39bf1ab0d2e327b0a192d2f5adcb4182de865411", | ||
"tsconfig": "0.0.0-next.39bf1ab0d2e327b0a192d2f5adcb4182de865411" | ||
"eslint-config-custom": "0.0.0-next.39c0188c3aa01bec7b64b948211571d5159e811d", | ||
"tsconfig": "0.0.0-next.39c0188c3aa01bec7b64b948211571d5159e811d" | ||
}, | ||
@@ -54,4 +55,3 @@ "engines": { | ||
"npm": ">=6.0.0" | ||
}, | ||
"gitHead": "39bf1ab0d2e327b0a192d2f5adcb4182de865411" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
33357
2