Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxvipon/4log
Line, HTTP Response and Error logger
https://github.com/maxvipon/4log
Last synced: 9 days ago
JSON representation
Line, HTTP Response and Error logger
- Host: GitHub
- URL: https://github.com/maxvipon/4log
- Owner: maxvipon
- License: mit
- Created: 2016-09-12T08:22:02.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-23T10:59:35.000Z (almost 8 years ago)
- Last Synced: 2024-10-30T14:24:45.295Z (17 days ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# 4log [![Build Status](https://travis-ci.org/maxvipon/4log.svg?branch=master)](https://travis-ci.org/maxvipon/4log)
> Line, HTTP Response and Error logger
## Install
```
$ npm install --save 4log
```## Usage
```js
const log = require('4log')('ctrl:index');log.msg('unicorns');
// Format: [datetime] [pid] type who "message"
// => [12/Sep/2016:11:56:51 +0500] [74640] MSG ctrl:index "unicorns"log.err(new Error('foobar'));
// Format: [datetime] [pid] type who "message" "stack"
// => [12/Sep/2016:09:53:28 +0300] [74640] ERR ctrl:index "ERROR: index returned tuples in wrong order" "Error: ERROR: index returned tuples in wrong order >> >> at Client._readError (/node_modules/pg-native/index.js:80:13) >> at Client._read (/node_modules/pg-native/index.js:121:19) >> at PQ.emit (events.js:104:17)"log.res(res);
// format: [datetime] [pid] type who IP "method url" status "message" "request_id"
// => [12/Sep/2016:11:34:00 +0300] [74640] RES ctrl:index 2a02:6b8:0:1625::6 "GET /v1/locations/foobar" 404 "Unsupported location" "7b5f10be25e111b2483f2b7e856feeac"
```## API
### log(name[, outStream[, errStream]])
#### name
Type: `String`
Name of the Logger instance.
#### outStream
Type: `Stream`
Default: `stdout`Writable stream for MSG and RES logs.
#### errStream
Type: `Stream`
Default: `stderr`Writable stream for ERR logs.
### log.msg(str[, arg1[, arg2,[ … argN]]])
#### str
Type: `String`
Sting for log. It may contain formatters `%s` or `%d` similar to `console.log`
### log.err(err)
#### err
Type: `Error`
### log.res(res[, err])
#### res
Type: `Response`
Express Response.
#### err
Type: `Error`
Error for logging response error.
## License
MIT © [Maxim Ponomarev](https://github.com/maxvipon)