@opuscapita/logger
Advanced tools
Comparing version 2.1.2 to 3.0.0
{ | ||
"name": "@opuscapita/logger", | ||
"version": "2.1.2", | ||
"version": "3.0.0", | ||
"description": "Unified logging component for OpusCapita Andariel platform.", | ||
"main": "./index.js", | ||
"main": "./index.mjs", | ||
"type": "commonjs", | ||
"types": "./types/index.d.ts", | ||
@@ -10,7 +11,4 @@ "module": "index.mjs", | ||
"start": "npm run test", | ||
"genTs": "npx -p typescript tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir types", | ||
"test:unit": "npx nyc --reporter=text --reporter=lcov mocha --bail '*.test.js'", | ||
"test:integ": "npx nyc --reporter=text --reporter=lcov mocha --bail 'test/*.spec.js' test/formatters/formatters.spec.js", | ||
"test": "npm run test:integ && npm run test:unit", | ||
"test-coverage": "npx nyc --reporter=lcov mocha", | ||
"genTs": "npx -p typescript tsc index.mjs --declaration --allowJs --emitDeclarationOnly --outDir types", | ||
"test": "npx vitest -c vite.config.js --coverage ", | ||
"doc": "npx documentation build -f html -o ./doc" | ||
@@ -43,16 +41,18 @@ }, | ||
"@opuscapita/eslint-config-opuscapita-bnapp": "^1.3.5", | ||
"@types/chai": "^4.3.5", | ||
"@types/chai": "^4.3.6", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^18.16.7", | ||
"chai": "^4.3.6", | ||
"@types/node": "^20.8.2", | ||
"@vitest/coverage-istanbul": "^0.34.6", | ||
"chai": "^4.3.10", | ||
"documentation": "^13.2.5", | ||
"eslint": "^8.20.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"mocha": "^10.0.0", | ||
"mocha-junit-reporter": "^2.0.2", | ||
"eslint": "^8.50.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"mocha": "^10.2.0", | ||
"mocha-junit-reporter": "^2.2.1", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"nyc": "^15.1.0", | ||
"typescript": "^5.0.4", | ||
"uuid": "^8.3.2" | ||
"typescript": "^5.2.2", | ||
"uuid": "^8.3.2", | ||
"vitest": "^0.34.6" | ||
} | ||
} |
@@ -13,19 +13,11 @@ export = Logger; | ||
/** | ||
* Creates a new instance of Logger. | ||
* @param {string|ILoggerConfig} [config] - Logger's name or a config object. | ||
* | ||
* @param {object} [config] - For a list of possible configuration values see [DefaultConfig]{@link DefaultConfig}. | ||
* @param {object} [config.context] Context data stored with every log entry | ||
* @param {string} [config.context.name] Name of your class/method that would be stored with every log entry | ||
* @param {object} [config.outputStreams] List of output streams for each log level (used for testing) | ||
* @param {Logger.LogLevel} [config.level] Default log level used when .log is called | ||
* | ||
* @constructor | ||
*/ | ||
constructor(config?: { | ||
context?: { | ||
name?: string; | ||
}; | ||
outputStreams?: object; | ||
level?: Logger.LogLevel; | ||
}); | ||
constructor(config?: string | ILoggerConfig); | ||
config: {}; | ||
_extractCallerName(stack: any): any; | ||
constructorStack: string; | ||
/** | ||
@@ -52,146 +44,112 @@ * Redirects all calls to console.log, console.info, console.debug, console.warn and console.error | ||
/** | ||
* Logs a message with the [LogLevel]{@link Logger.LogLevel} "Debug". | ||
* Most detailed information. Expect these to be written to logs only. | ||
* Method for changing the context of log messages. A context can either be specified using the constructor's | ||
* config value (see [DefaultConfig]{@link Logger.DefaultConfig}) or this method. Every time .contextify() is called, | ||
* all following log message will populate the passed context as general meta data in every log entry. | ||
* | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* Be aware that the passed context object will always be extended by the defaul context object from [DefaultConfig]{@link Logger.DefaultConfig}. | ||
* In order to fully remove all basic information from beeing populated, set the context object to an empty | ||
* object when calling the constructor of this class. | ||
* | ||
* @param {object} context - Context object. | ||
* | ||
* @deprecated since 1.6.1 - use `new Logger({context:{}})` instead | ||
*/ | ||
trace(message: string, payload?: any, ...args: any[]): void; | ||
contextify(context: any): void; | ||
/** | ||
* Logs a message with the [LogLevel]{@link Logger.LogLevel} "Debug". | ||
* Detailed information on the flow through the system. Expect these to be written to logs only. | ||
* Generally speaking, most lines logged by your application should be written as DEBUG. | ||
* Creates a deep copy of a Logger object and returns it. | ||
* @returns {Logger} The cloned Logger object. | ||
* | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* @deprecated since 1.6.1 - create a new instance of logger instead using `new Logger()` | ||
*/ | ||
debug(message: string, payload?: any, ...args: any[]): void; | ||
clone(): import("."); | ||
} | ||
declare namespace Logger { | ||
export { serviceName, LogLevel, DefaultConfig, IContext, IOutputStreams, ILoggerConfig, ILogFunction }; | ||
} | ||
type ILoggerConfig = { | ||
/** | ||
* Logs a message with the [LogLevel]{@link Logger.LogLevel} "Info". | ||
* Interesting runtime events (startup/shutdown). | ||
* Expect these to be immediately visible on a console, so be conservative and keep to a minimum. | ||
* | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* - Object containing different output streams for different log levels. | ||
*/ | ||
info(message: string, payload?: any, ...args: any[]): void; | ||
outputStreams?: IOutputStreams; | ||
/** | ||
* Logs a message with the [LogLevel]{@link Logger.LogLevel} "Warning". | ||
* Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". | ||
* Expect these to be immediately visible on a status console. | ||
* | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* - Context data stored with every log entry | ||
*/ | ||
warn(message: string, payload?: any, ...args: any[]): void; | ||
context?: IContext; | ||
/** | ||
* Logs a message with the [LogLevel]{@link Logger.LogLevel} "Error". | ||
* Other runtime errors or unexpected conditions. | ||
* Expect these to be immediately visible on a status console. | ||
* | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* - The default log level when no matching configuration is found | ||
*/ | ||
error(message: string, payload?: any, ...args: any[]): void; | ||
level?: Logger.LogLevel; | ||
}; | ||
declare var serviceName: string; | ||
/** | ||
* Enumeration representing all available log levels to log messages. | ||
*/ | ||
type LogLevel = string; | ||
declare var LogLevel: Readonly<{ | ||
Trace: "trace"; | ||
Debug: "debug"; | ||
Info: "info"; | ||
Warn: "warn"; | ||
Warning: "warn"; | ||
Error: "error"; | ||
Fatal: "fatal"; | ||
}>; | ||
declare var DefaultConfig: ILoggerConfig; | ||
/** | ||
* - Context data stored with every log entry | ||
*/ | ||
type IContext = { | ||
/** | ||
* Logs a message with the [LogLevel]{@link Logger.LogLevel} "Exception". | ||
* | ||
* @deprecated since 2.0.0 - pass exception message as a parameter to other log levels instead | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* - Name of your class/method that would be stored with every log entry (extracted from stack if not provided)) | ||
*/ | ||
except(message: string, payload?: any, ...args: any[]): void; | ||
name?: string; | ||
/** | ||
* Logs a message with the [LogLevel]{@link Logger.LogLevel} "Fatal". | ||
* Severe errors that cause premature termination. | ||
* Expect these to be immediately visible on a status console. | ||
* | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* - Name of your service that would be stored with every log entry (defaults to project's directory name) | ||
*/ | ||
fatal(message: string, payload?: any, ...args: any[]): void; | ||
serviceName?: string; | ||
/** | ||
* Logs a message with the default [LogLevel]{@link Logger.LogLevel} passed to the constructor. | ||
* For further information see [DefaultConfig]{@link Logger.DefaultConfig}. | ||
* | ||
* @Deprecated since 2.0.0 | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* - User ID that would be stored with every log entry (in Andariel it is injected/overwritten by the middleware) | ||
*/ | ||
log(message: string, payload?: any, ...args: any[]): void; | ||
userId?: string; | ||
/** | ||
* Logs a message with the default [LogLevel]{@link Logger.LogLevel} passed to the constructor. | ||
* For further information see [DefaultConfig]{@link Logger.DefaultConfig}. | ||
* | ||
* @param {string} message - Static message to log | ||
* @param {object} [payload] - A variable payload which keys would be stringified and logged along with the log entry. | ||
* - Request URI that would be stored with every log entry (in Andariel it is injected/overwritten by the middleware) | ||
*/ | ||
write(message: string, payload?: any, ...args: any[]): void; | ||
requestUri?: string; | ||
/** | ||
* Method for changing the context of log messages. A context can either be specified using the constructor's | ||
* config value (see [DefaultConfig]{@link Logger.DefaultConfig}) or this method. Every time .contextify() is called, | ||
* all following log message will populate the passed context as general meta data in every log entry. | ||
* | ||
* Be aware that the passed context object will always be extended by the defaul context object from [DefaultConfig]{@link Logger.DefaultConfig}. | ||
* In order to fully remove all basic information from beeing populated, set the context object to an empty | ||
* object when calling the constructor of this class. | ||
* | ||
* @param {object} context - Context object. | ||
* | ||
* @deprecated since 1.6.1 - use `new Logger({context:{}})` instead | ||
* - Correlation ID that would be stored with every log entry (in Andariel it is injected/overwritten by the middleware) | ||
*/ | ||
contextify(context: any): void; | ||
correlationId?: string; | ||
}; | ||
type IOutputStreams = { | ||
/** | ||
* Creates a deep copy of a Logger object and returns it. | ||
* @returns {Logger} The cloned Logger object. | ||
* | ||
* @deprecated since 1.6.1 - create a new instance of logger instead using `new Logger()` | ||
* - Output stream for {@link Logger.LogLevel } "Trace" | ||
*/ | ||
clone(): Logger; | ||
} | ||
declare namespace Logger { | ||
const serviceName: string; | ||
trace: NodeJS.WritableStream; | ||
/** | ||
* Enumeration representing all available log levels to log messages. | ||
* - Output stream for {@link Logger.LogLevel } "Debug" | ||
*/ | ||
type LogLevel = string; | ||
const LogLevel: Readonly<{ | ||
Invalid: ""; | ||
Trace: "trace"; | ||
Debug: "debug"; | ||
Info: "info"; | ||
Warn: "warn"; | ||
Warning: "warn"; | ||
Error: "error"; | ||
Fatal: "fatal"; | ||
Exception: "exception"; | ||
}>; | ||
namespace DefaultConfig { | ||
import level = Info; | ||
export { level }; | ||
export namespace outputStreams { | ||
const trace: NodeJS.WriteStream & { | ||
fd: 1; | ||
}; | ||
const debug: NodeJS.WriteStream & { | ||
fd: 1; | ||
}; | ||
const info: NodeJS.WriteStream & { | ||
fd: 1; | ||
}; | ||
const warn: NodeJS.WriteStream & { | ||
fd: 1; | ||
}; | ||
const error: NodeJS.WriteStream & { | ||
fd: 2; | ||
}; | ||
const fatal: NodeJS.WriteStream & { | ||
fd: 2; | ||
}; | ||
const exception: NodeJS.WriteStream & { | ||
fd: 2; | ||
}; | ||
} | ||
export const context: {}; | ||
} | ||
} | ||
debug: NodeJS.WritableStream; | ||
/** | ||
* - Output stream for {@link Logger.LogLevel } "Info" | ||
*/ | ||
info: NodeJS.WritableStream; | ||
/** | ||
* - Output stream for {@link Logger.LogLevel } "Warning" | ||
*/ | ||
warn: NodeJS.WritableStream; | ||
/** | ||
* - Output stream for {@link Logger.LogLevel } "Error" | ||
*/ | ||
error: NodeJS.WritableStream; | ||
/** | ||
* - Output stream for {@link Logger.LogLevel } "Fatal" | ||
*/ | ||
fatal: NodeJS.WritableStream; | ||
}; | ||
/** | ||
* A function to log a message with a specific log level. | ||
* | ||
* Roughly based on the console.log() function where first argument is a fixed string with optional substitution strings. | ||
* Second parameter should be an object with key/value pairs that would be stringified and logged along with the log entry. Original function allowed multipe parameters but then we would loose the parameter names. | ||
*/ | ||
type ILogFunction = Function; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
14079
16
3
153
1