diff --git a/README.md b/README.md index af1ef07..0d1dd38 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ Features: * Add or use your own streams for destinations * All pino-pretty configs are exposed and extensible + + # Install ``` @@ -225,7 +228,7 @@ import { buildDestinationStdout, // stream to STDOUT buildDestinationStderr, // stream to STDERR buildDestinationFile, // write to static file - buildDestinationRollingFile // write to rolling + buildDestinationRollingFile // write to rolling file } from "@foxxmd/logging/factory"; ``` @@ -234,7 +237,7 @@ All `buildDestination` functions take args: * `level` (first arg) - minimum level to log at * `options` (second arg) - an object extending [`pino-pretty` options](https://github.com/pinojs/pino-pretty?tab=readme-ov-file#options) -`options` inherits a default `pino-pretty` configuration that makes comprises `@foxxmd/logging`'s opinionated logging format. The common default config can be generated using `prettyOptsFactory` which accepts an optional [`pino-pretty` options](https://github.com/pinojs/pino-pretty?tab=readme-ov-file#options) object to override defaults: +`options` inherits a default `pino-pretty` configuration that comprises `@foxxmd/logging`'s opinionated logging format. The common default config can be generated using `prettyOptsFactory` which accepts an optional [`pino-pretty` options](https://github.com/pinojs/pino-pretty?tab=readme-ov-file#options) object to override defaults: ```ts import { prettyOptsFactory } from "@foxxmd/logging/factory"; diff --git a/example/example.png b/example/example.png new file mode 100644 index 0000000..a9bbfd7 Binary files /dev/null and b/example/example.png differ diff --git a/example/kitchenSink.ts b/example/kitchenSink.ts new file mode 100644 index 0000000..652905e --- /dev/null +++ b/example/kitchenSink.ts @@ -0,0 +1,31 @@ +import {childLogger, loggerApp, loggerDebug} from '../src/index.js' +import {ErrorWithCause} from "pony-cause"; +import process from "process"; +import path from 'path'; + +const initLogger = childLogger(loggerDebug, 'Init'); +initLogger.info('Initializing Application -> v1.3.1'); +initLogger.debug('Debug logging is enabled!'); +initLogger.debug(`Found Log Config at ${path.resolve(process.cwd(), './config.yaml')}`) + +const appLogger = loggerApp({file: false}); +const logger = childLogger(appLogger, 'App'); +logger.verbose(`Logging to -> ${path.resolve(process.cwd(), './logs/app.log')}`); + +const nestedChild1 = childLogger(logger, 'Service A'); +nestedChild1.log('Starting monitoring for events...'); + +const nestedChild2 = childLogger(nestedChild1, ['Queue', 'Parser']); +nestedChild2.warn('Unexpected contents found in event, skipping'); + +const siblingLogger = childLogger(logger, ['Service B', 'Manager']); +siblingLogger.info('Widget allocation has initiated'); + +logger.debug({myProp: 'a string', nested: {anotherProps: ['val1', 'val2'], boolProp: true}}, 'Test'); + +const er = new Error('A configuration error occurred'); +const causeErr = new ErrorWithCause('Service C did not start', {cause: er}); +logger.error(causeErr); + +logger.verbose('(1) service failed to start but is non-essential...continuing startup') +logger.info('Application successfully started and running!') diff --git a/package.json b/package.json index ead4a13..46e79c8 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "build": "tsc", "prepare": "tshy", "test": "mocha --reporter spec --recursive ./tests/*.test.ts", - "postinstall": "patch-package" + "postinstall": "patch-package", + "example": "tsx example/kitchenSink.ts" }, "keywords": [], "author": "FoxxMD",