@strapi/logger
Advanced tools
Comparing version 0.0.0-experimental.ccba4ea6043b6bab83888f85cc9a3f07f61dc262 to 0.0.0-experimental.ce3ce68ff05de341bbdb48e7164d5367cffa839c
@@ -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-experimental.ccba4ea6043b6bab83888f85cc9a3f07f61dc262", | ||
"version": "0.0.0-experimental.ce3ce68ff05de341bbdb48e7164d5367cffa839c", | ||
"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-experimental.ccba4ea6043b6bab83888f85cc9a3f07f61dc262", | ||
"tsconfig": "0.0.0-experimental.ccba4ea6043b6bab83888f85cc9a3f07f61dc262" | ||
"eslint-config-custom": "0.0.0-experimental.ce3ce68ff05de341bbdb48e7164d5367cffa839c", | ||
"tsconfig": "0.0.0-experimental.ce3ce68ff05de341bbdb48e7164d5367cffa839c" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0 <=20.x.x", | ||
"node": ">=18.0.0 <=22.x.x", | ||
"npm": ">=6.0.0" | ||
}, | ||
"gitHead": "ccba4ea6043b6bab83888f85cc9a3f07f61dc262" | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
33381
2
28
287
1
80