https://github.com/byu-oit/logger
Default configuration for pino logger to match Application Development logging standards
https://github.com/byu-oit/logger
Last synced: about 2 months ago
JSON representation
Default configuration for pino logger to match Application Development logging standards
- Host: GitHub
- URL: https://github.com/byu-oit/logger
- Owner: byu-oit
- License: apache-2.0
- Created: 2021-04-05T16:21:21.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T16:29:32.000Z (almost 2 years ago)
- Last Synced: 2025-12-07T00:14:52.580Z (8 months ago)
- Language: TypeScript
- Size: 455 KB
- Stars: 0
- Watchers: 20
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BYU Logger
[]()
[](https://codecov.io/gh/byu-oit/logger)
Creates a [`pino` logger](https://github.com/pinojs/pino) with default settings to match the [CES Application Development logging standards](https://github.com/byu-oit/ces-dev-best-practices/blob/main/adr/application/0006-basic-logging-standards.md).
It will pretty-print logs when run locally, but it will write logs in JSON when deployed (when `NODE_ENV=production`).
## Install
```
npm i @byu-oit/logger
```
## Usage
```typescript
import DefaultLogger from '@byu-oit/logger'
const logger = DefaultLogger()
logger.info('Hello World')
logger.warn('Something weird happened')
logger.error(new Error('Something went wrong!'))
```
CommonJS Equivalent
```javascript
const { default: DefaultLogger } = require('@byu-oit/logger')
const logger = DefaultLogger()
logger.info('Hello World')
logger.warn('Something weird happened')
logger.error(new Error('Something went wrong!'))
```
---
The semantics are slightly different than functions like `console.log()` and `console.error()`.
Namely,
```typescript
console.error('Something went wrong in X:', new Error('the error'))
```
would be roughly equivalent to
```typescript
logger.error(new Error('the error'), 'Something went wrong in X')
```
For more details, see the `pino` documentation [here](https://github.com/pinojs/pino/blob/master/docs/api.md#logger-instance).
## Options
Any [`pino` options](https://github.com/pinojs/pino/blob/master/docs/api.md#options) can be overridden, but for compliance with our logging standards, we recommend sticking to the defaults provided in this package.
### Example of overwriting a default
```typescript
import DefaultLogger from "./logger"
const logger = DefaultLogger({ level: 'trace' })
```