https://github.com/strigo/strigo-node-logger
Strigo's logger for node applications
https://github.com/strigo/strigo-node-logger
ecs elastic-common-schema logging logging-library nodejs
Last synced: 5 months ago
JSON representation
Strigo's logger for node applications
- Host: GitHub
- URL: https://github.com/strigo/strigo-node-logger
- Owner: strigo
- Created: 2019-01-01T21:03:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-10T03:29:02.000Z (over 4 years ago)
- Last Synced: 2023-03-02T18:56:01.811Z (over 3 years ago)
- Topics: ecs, elastic-common-schema, logging, logging-library, nodejs
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# strigo-node-logger
A NodeJS logger instrumentation library for Strigo applications.
This is a light abstraction over a common logger.
It provides a way to setup the logger for various applications, defaults as to where to direct logs in different cases, and a way to determine context for entries in a generic way.
The logger is built around the [winston logger](https://github.com/winstonjs/winston), and
[express-winston](https://github.com/bithavoc/express-winston) when used as middleware for Express.js.
Make sure to go over the `winston` & `express-winston` docs to know the API of the logger.
For Express.js specifically, make sure to [read this](https://github.com/bithavoc/express-winston#error-logging) about binding order of the error logging middleware.
## Installation
Add `"@strigo/node-logger": "strigo/strigo-node-logger.git#TAG"` to your `package.json`.
## Usage
### In a vanilla node application
```javascript
import { setupNodeLogger } from '@strigo/node-logger';
const log = setupNodeLogger({ json = true, level = 'info' });
log.info(...);
log.level = 'debug';
log.debug(...);
// And so on...
```
### In an ExpressJS application
```javascript
import { setupExpressLogger } from '@strigo/node-logger';
const { log, loggerMiddleware, errorLoggerMiddleware } = setupExpressLogger({});
app.use(loggerMiddleware);
// read docs about error logger
app.use(errorLoggerMiddleware);
log.info(...);
// And so on...
```
Check [examples](examples) for more info.