[READ-ONLY] Mirror of https://github.com/FoxxMD/logging. A typed, opinionated, batteries-included, Pino-based logging solution for backend TS/JS projects foxxmd.github.io/logging
child-logger logging logging-library nodejs pinojs typescript-library
0

Configure Feed

Select the types of activity you want to include in your feed.

docs: Add runkit example

FoxxMD (Mar 8, 2024, 2:06 PM EST) d1354e2c c4da97a7

+34
+1
README.md
··· 2 2 3 3 [![Latest Release](https://img.shields.io/github/v/release/foxxmd/logging)](https://github.com/FoxxMD/logging/releases) 4 4 [![NPM Version](https://img.shields.io/npm/v/%40foxxmd%2Flogging)](https://www.npmjs.com/package/@foxxmd/logging) 5 + [![Try on Runkit](https://img.shields.io/static/v1?label=Try%20it%20online%20on&message=RunKit&color=f55fa6)](https://npm.runkit.com/%40foxxmd%2Flogging) 5 6 [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 6 7 7 8 A typed, opinionated, batteries-included, [Pino](https://getpino.io)-based logging solution for backend TS/JS projects.
+32
example/runkit.js
··· 1 + const logging = require('@foxxmd/logging'); 2 + const ec = require('pony-cause'); 3 + 4 + const {childLogger, loggerApp, loggerDebug} = logging; 5 + const {ErrorWithCause} = ec; 6 + 7 + const initLogger = childLogger(loggerDebug, 'Init'); 8 + initLogger.info('Initializing Application -> v1.3.1'); 9 + initLogger.debug('Debug logging is enabled!'); 10 + initLogger.debug(`Found Log Config at path/to/config.yaml`) 11 + 12 + const appLogger = loggerApp({file: false}); 13 + const logger = childLogger(appLogger, 'App'); 14 + logger.verbose(`Logging to -> path/to/logs/app.log`); 15 + 16 + const nestedChild1 = childLogger(logger, 'Service A'); 17 + nestedChild1.log('Starting monitoring for events...'); 18 + 19 + const nestedChild2 = childLogger(nestedChild1, ['Queue', 'Parser']); 20 + nestedChild2.warn('Unexpected contents found in event, skipping'); 21 + 22 + const siblingLogger = childLogger(logger, ['Service B', 'Manager']); 23 + siblingLogger.info('Widget allocation has initiated'); 24 + 25 + logger.debug({myProp: 'a string', nested: {anotherProps: ['val1', 'val2'], boolProp: true}}, 'Test'); 26 + 27 + const er = new Error('A configuration error occurred'); 28 + const causeErr = new ErrorWithCause('Service C did not start', {cause: er}); 29 + logger.error(causeErr); 30 + 31 + logger.verbose('(1) service failed to start but is non-essential...continuing startup') 32 + logger.info('Application successfully started and running!')
+1
package.json
··· 11 11 "test": "mocha --reporter spec --recursive ./tests/*.test.ts", 12 12 "example": "tsx example/kitchenSink.ts" 13 13 }, 14 + "runkitExampleFilename": "example/runkit.js", 14 15 "keywords": [], 15 16 "author": "FoxxMD", 16 17 "license": "MIT",