Logging helper for Javascript/Typescript
npm install @simplyappdevs/logging-helperconsole.log everywhere in my code. So this module allows me to standardize log statements with certain format.
javascript
export interface LogEntry {
logType: LOGTYPES; // Log type
appName: string; // Application name
modName: string; // Module name
fnName: string; // Function name
entryTS: Date; // Log entry timestamp in UTC
friendlyMsg: string; // Log friendly/brief message
detailMsg?: string; // Log detail message (ex: StackTrace from Error)
task?: string; // Step/task being executed
durationIsMS?: number; // Duration taken in millisecond
}
export interface LogEntryWithDuration extends LogEntry {
endTS: Date; // Log entry end timestamp in UTC
durationIsMS?: number; // Duration taken in millisecond
}
`
Loggers
$3
> Logger that takes all parameters
$3
> High-order logger on top of main logger to pin the module name
$3
> High-order logger on top of module logger to pin the function name
Log Output Override
This logger helper module does not actually output the log entries. It expects a logger output to be assigned via setLoggerOutput() function available from the main logger interface.
`javascript
export type LoggerOutput = (entry: Readonly | Readonly) => void;
`
Example
> https://github.com/simplyappdevs/logging-helper-example
Reminder for ESM Application
$3
> You will need to run your application with --es-module-specifier-resolution=node option.
>
> Ex: "exec": "node --es-module-specifier-resolution=node ./dist/index.js" for your NPM script npm run exec.
$3
> Set type to module "type": "module"
`json
{
"name": "my-awesome-app",
"version": "1.0.0",
"description": "My Awesome App",
"main": "index.js",
"type": "module",
"scripts": {
}
}
`
$3
> Set module to one of ECMA script "module": "esnext" in compilerOptions section
`json
{
"compilerOptions": {
"module": "esnext",
}
}
`
> Set module resolution to node "moduleResolution": "node" in compilerOptions section
`json
{
"compilerOptions": {
"moduleResolution": "node",
}
}
``