Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/littlstar/web-lager
[DEPRECATED] Flexible logger with Express access logging and S3 integration
https://github.com/littlstar/web-lager
Last synced: about 2 months ago
JSON representation
[DEPRECATED] Flexible logger with Express access logging and S3 integration
- Host: GitHub
- URL: https://github.com/littlstar/web-lager
- Owner: littlstar
- License: mit
- Created: 2016-01-12T16:32:48.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-31T16:59:08.000Z (over 8 years ago)
- Last Synced: 2024-08-09T13:16:35.977Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 3
- Watchers: 10
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# web-lager
General-purpose logger that supports multiple log levels and transports. Express framework access logging is built in, which makes this an ideal server-side logger. By default, all logs are sent to `stdout` or `stderr`.
### Install
```
npm i web-lager --save
```### Basic Usage
Send logs to two different S3 buckets based on log level
```javascript
var Logger = require('web-lager');var transports = [{
// flushes access logs to s3://my-bucket/access/ every minute
type: 's3',
bucket: 'my-bucket',
prefix: 'access/',
levels: ['access'],
frequency: '* * * * *'
}, {// flushes errors to s3://my-bucket/error-logs/ every hour
type: 's3',
bucket: 'my-bucket',
prefix: 'error-logs/',
levels: ['error', 'warn'],
frequency: '0 * * * *'
};var logger = new Logger({
transports: transports
});```
### Express Access Logging
Enable access logging in your Express server by calling `accessLogMiddleware`.
```javascript
var express = require('express');
var Logger = require('web-lager');
var app = express();
var logger = new Logger();// enables access logging from Express
app.use(logger.accessLogger());
```### Skip Access Logs
If you want to ignore certain access logs from Express (such as a health check),
you can do so by defining a skip function in the config.
```javascript
var express = require('express');
var Logger = require('web-lager');
var app = express();var config = {
access: {// Example: skips logs that have a 400+ level status code
skip: (req, res) => res.statusCode < 400
}
};var logger = new Logger(config);
app.use(logger.accessLogger());
```### Supported Levels
- access
- log
- info
- debug
- warn
- error