https://github.com/baileyherbert/logging
Just another logging solution for Node.js applications.
https://github.com/baileyherbert/logging
logging nodejs
Last synced: 5 months ago
JSON representation
Just another logging solution for Node.js applications.
- Host: GitHub
- URL: https://github.com/baileyherbert/logging
- Owner: baileyherbert
- License: mit
- Created: 2021-11-21T00:02:28.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-21T20:27:06.000Z (over 2 years ago)
- Last Synced: 2025-10-30T00:59:23.565Z (8 months ago)
- Topics: logging, nodejs
- Language: TypeScript
- Homepage: https://www.npmjs.com/@baileyherbert/logging
- Size: 1.22 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
github /
npm /
documentation
# logging
An elegant logging solution for TypeScript built on a hierarchical composite pattern.
```
npm install @baileyherbert/logging
```
## examples
### creating the root logger
Each application needs at least one root logger instance.
```ts
const rootLogger = new Logger();
```
### attaching transports to the root logger
The root logger is responsible for piping its output into one or more transports. The example below will create and attach a [console transport](https://docs.bailey.sh/logging/latest/guide/transports/) to the logger, which writes logs directly to the console. This works in a browser environment.
```ts
rootLogger.createConsoleTransport();
```
### creating child loggers
Each service in your application should have its own logger instance. These are called child loggers, and they are used to automatically prefix output from services with their names.
```ts
const logger = rootLogger.createChild('ServiceName');
```
### writing logs
Loggers expose methods for each supported severity level.
```ts
logger.trace();
logger.debug();
logger.info();
logger.warning();
logger.error();
logger.critical();
```
These methods work identically to `console.log()`. You can pass multiple parameters of any type, and can pass a string for formatting.
```ts
logger.info('Logged in as %s from %s', username, ip);
```
## license
MIT