|
| 1 | +import {childLogger, loggerApp, loggerDebug} from '../src/index.js' |
| 2 | +import {ErrorWithCause} from "pony-cause"; |
| 3 | +import process from "process"; |
| 4 | +import path from 'path'; |
| 5 | + |
| 6 | +const initLogger = childLogger(loggerDebug, 'Init'); |
| 7 | +initLogger.info('Initializing Application -> v1.3.1'); |
| 8 | +initLogger.debug('Debug logging is enabled!'); |
| 9 | +initLogger.debug(`Found Log Config at ${path.resolve(process.cwd(), './config.yaml')}`) |
| 10 | + |
| 11 | +const appLogger = loggerApp({file: false}); |
| 12 | +const logger = childLogger(appLogger, 'App'); |
| 13 | +logger.verbose(`Logging to -> ${path.resolve(process.cwd(), './logs/app.log')}`); |
| 14 | + |
| 15 | +const nestedChild1 = childLogger(logger, 'Service A'); |
| 16 | +nestedChild1.log('Starting monitoring for events...'); |
| 17 | + |
| 18 | +const nestedChild2 = childLogger(nestedChild1, ['Queue', 'Parser']); |
| 19 | +nestedChild2.warn('Unexpected contents found in event, skipping'); |
| 20 | + |
| 21 | +const siblingLogger = childLogger(logger, ['Service B', 'Manager']); |
| 22 | +siblingLogger.info('Widget allocation has initiated'); |
| 23 | + |
| 24 | +logger.debug({myProp: 'a string', nested: {anotherProps: ['val1', 'val2'], boolProp: true}}, 'Test'); |
| 25 | + |
| 26 | +const er = new Error('A configuration error occurred'); |
| 27 | +const causeErr = new ErrorWithCause('Service C did not start', {cause: er}); |
| 28 | +logger.error(causeErr); |
| 29 | + |
| 30 | +logger.verbose('(1) service failed to start but is non-essential...continuing startup') |
| 31 | +logger.info('Application successfully started and running!') |
0 commit comments