@strapi/logger
Advanced tools
Comparing version 0.0.0-experimental.44c735643fa8b4286750c2dca43f185bb30b7760 to 0.0.0-experimental.457ea3914b4550fd60261e9e99d4501c5d1702cb
@@ -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,88 +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, 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({ | ||
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; | ||
@@ -110,0 +137,0 @@ exports.configs = index; |
{ | ||
"name": "@strapi/logger", | ||
"version": "0.0.0-experimental.44c735643fa8b4286750c2dca43f185bb30b7760", | ||
"version": "0.0.0-experimental.457ea3914b4550fd60261e9e99d4501c5d1702cb", | ||
"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,11 +48,9 @@ "dependencies": { | ||
"devDependencies": { | ||
"@strapi/pack-up": "5.0.0", | ||
"eslint-config-custom": "0.0.0-experimental.44c735643fa8b4286750c2dca43f185bb30b7760", | ||
"tsconfig": "0.0.0-experimental.44c735643fa8b4286750c2dca43f185bb30b7760" | ||
"eslint-config-custom": "0.0.0-experimental.457ea3914b4550fd60261e9e99d4501c5d1702cb", | ||
"tsconfig": "0.0.0-experimental.457ea3914b4550fd60261e9e99d4501c5d1702cb" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0 <=20.x.x", | ||
"node": ">=18.0.0 <=22.x.x", | ||
"npm": ">=6.0.0" | ||
}, | ||
"gitHead": "44c735643fa8b4286750c2dca43f185bb30b7760" | ||
} | ||
} |
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
33381
2
28
287