@strapi/logger
Advanced tools
Comparing version 0.0.0-next.16afe21665d27a27f5c86939ba362066eabf1982 to 0.0.0-next.16cb0821de17dd12078d915e3a10249158807e5e
@@ -1,4 +0,4 @@ | ||
import { LoggerOptions } from 'winston'; | ||
declare const _default: (filename: string) => LoggerOptions; | ||
import { transports, LoggerOptions } from 'winston'; | ||
declare const _default: (filename: string, fileTransportOptions?: transports.FileTransportOptions) => LoggerOptions; | ||
export default _default; | ||
//# sourceMappingURL=output-file-configuration.d.ts.map |
@@ -5,2 +5,3 @@ export { default as prettyPrint } from './pretty-print'; | ||
export { default as excludeColors } from './exclude-colors'; | ||
export { default as detailedLogs } from './detailed-log'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,18 +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]; } | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -22,83 +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 index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
var levelFilter = ((...levels)=>{ | ||
return winston.format((info)=>levels.some((level)=>info.level.includes(level)) ? info : false)(); | ||
}); | ||
/** | ||
* 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, | ||
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) => { | ||
return { | ||
level: LEVEL_LABEL, | ||
levels: LEVELS, | ||
format: prettyPrint(), | ||
transports: [ | ||
new winston.transports.Console(), | ||
new winston.transports.File({ level: "error", filename, format: excludeColors }) | ||
] | ||
}; | ||
}; | ||
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
detailedLogs: detailedLog, | ||
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; | ||
@@ -105,0 +137,0 @@ exports.configs = index; |
{ | ||
"name": "@strapi/logger", | ||
"version": "0.0.0-next.16afe21665d27a27f5c86939ba362066eabf1982", | ||
"version": "0.0.0-next.16cb0821de17dd12078d915e3a10249158807e5e", | ||
"description": "Strapi's logger", | ||
@@ -31,10 +31,12 @@ "homepage": "https://strapi.io", | ||
"files": [ | ||
"./dist" | ||
"dist/" | ||
], | ||
"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,11 +48,9 @@ "dependencies": { | ||
"devDependencies": { | ||
"@strapi/pack-up": "4.23.0", | ||
"eslint-config-custom": "0.0.0-next.16afe21665d27a27f5c86939ba362066eabf1982", | ||
"tsconfig": "0.0.0-next.16afe21665d27a27f5c86939ba362066eabf1982" | ||
"eslint-config-custom": "0.0.0-next.16cb0821de17dd12078d915e3a10249158807e5e", | ||
"tsconfig": "0.0.0-next.16cb0821de17dd12078d915e3a10249158807e5e" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0 <=20.x.x", | ||
"node": ">=18.0.0 <=22.x.x", | ||
"npm": ">=6.0.0" | ||
}, | ||
"gitHead": "16afe21665d27a27f5c86939ba362066eabf1982" | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33357
2
28
287
0