log-segment
javascript logger with partition
Purpose
Quickly manage logs by two level and segment.
Install
$ npm i log-segment --save
Quick start
log-segment
is singleton, so just require and use everywhere.
const log = const sql = 'INSERT INTO users (username, name) VALUES ($1, $2)'logdb
const log = all'/*' { log }
Default settings
Default settings provide any levels and segments enabled to console output.
Default levels are: info, success, warning, error, panic.
There is no hierarchy by levels.
levels: '*': color: 'white' info: color: 'blue' marker: 'ℹ️' success: color: 'green' marker: '✔' warning: color: 'yellow' marker: '❗️️' error: color: 'red' marker: '✗️' panic: color: 'magenta' marker: '😱' segments: '*': color: 'white' format: '{segment} | {marker} [{timestamp}] {message}' enabled: segments: '*' levels: '*'
Custom segments
const log = log const sql = 'INSERT INTO table ...' loglog const request = method: 'GET' baseUrl: '/it/4x/api.html#req' const err = 'file not found' loglog let username = nulllog
Custom levels
const log = log const sql = 'INSERT INTO table ...' loglog const request = method: 'GET' baseUrl: '/it/4x/api.html#req' const err = 'file not found' loglog let username = nulllog
Custom format
Default format is '{segment} | {marker} [{timestamp}] {message}'
.
You can optionally add {trace}
to format and it will implicitly add trace information
log
Use Cases
log
Development
Just enable everything on console
log
Debug
Enable only segments to focus on, at any levels, to find that bug
log
Beta
Enable all segments, disable info and success level
log
Production
Different behaviour for each level:
- disable not interesting parts: success level
- different file for each type: info, warning, error and remove marks
- separate sql file
- on panic send email
log
Documentation
See documentation for further informations.
Changelog
v. 1.7.0
- Add custom format to
level
, optionally add{segment}
- Default format review as
'{segment} | {marker} [{timestamp}] {message}'
v. 1.6.0
- Add chrono function
log.chrono('tag')
v. 1.3.0
- Add customizable output default format
- Add message info
trace
,timestamp
v. 1.2.0
- Add
.check()
to check settings for- console > color
- files > write permission
- emails > sending settings
v. 1.1.0
- Add support for email mode
TODO
- bdd test / tollo
- pre-commit
- travis ci
- browser support, only console mode (!colors)
console.log('%c message', 'color: red');
- custom format in log.value
- custom mode: stream (sms, telegram and whatever)
- multiple mode for each setting (example: on panic send email + log to file + send sms + call mom)
- support workers (as transport)
License
The MIT License (MIT)
Copyright (c) 2017-2018, braces lab
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.