Skip to content

Commit

Permalink
docs: Add kitchensink example generator and screenshot to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Mar 7, 2024
1 parent e5214c2 commit 58424b9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Features:
* Add or use your own streams for destinations
* All pino-pretty configs are exposed and extensible

<img src="/example/example.png"
alt="log output example" height="500">

# Install

```
Expand Down Expand Up @@ -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";
```

Expand All @@ -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";
Expand Down
Binary file added example/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions example/kitchenSink.ts
Original file line number Diff line number Diff line change
@@ -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!')
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 58424b9

Please sign in to comment.