Skip to content

Commit 38fca1e

Browse files
committed
Update README
1 parent 9253f1d commit 38fca1e

1 file changed

Lines changed: 45 additions & 42 deletions

File tree

README.md

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,80 @@
11
# Monk Log library
22

3-
This is a simple logging library for Nodejs projects depends on:
4-
- [loglevel](https://github.com/pimterry/loglevel)
5-
- [loglevel-plugin-prefix](https://github.com/kutuluk/loglevel-plugin-prefix)
6-
- [chalk](https://github.com/chalk/chalk#readme)
3+
Are you using `console.log` in your project? Are you tired of configuring
4+
loglevel / winston / whatever to add timestamp, colors to your log messages?
5+
Do you want a consistent log style?
6+
This is the library for you! You can now log with style -- no configuration
7+
required!
78

89
## Installation
910

10-
For add this as `npm` dependency
11+
Simply add this library as a dependency in your project.
12+
You can use the github URI:
1113

12-
```bash
13-
npm install git+ssh://git@git.webmonks.org:node-libraries/monk-log.git
14+
```
15+
yarn add github:monksoftware/monk-log
1416
```
1517

1618
or add manually to your `package.json` file
1719

1820
```json
1921
{
2022
"dependencies": {
21-
... ,
22-
"monk-log": "git+ssh://git@git.webmonks.org:node-libraries/monk-log.git"
23+
[...] ,
24+
"monk-log": "github:monksoftware/monk-log"
2325
}
2426
}
2527
```
2628

27-
## Setting up
29+
## How to use
30+
31+
Works pretty much the same as `loglevel`, the only difference is that
32+
the exported root logger is preconfigured with loglevel-plugin-prefix
33+
and custom formatting functions in order to output nice colorful log messages
34+
with timestamp, log level and logger name.
2835

2936
```javascript
30-
const { levels, monkLog } = require('monk-log')
31-
const log = monkLog(options)
37+
const log = require('monk-log')
3238

3339
log.trace(msg)
3440
log.debug(msg)
3541
log.info(msg)
3642
log.warn(msg)
3743
log.error(msg)
38-
39-
```
40-
41-
## Documentation
42-
43-
The monk log library accept optional parameters:
44-
```
45-
{
46-
name: // Choose a name for log instance, default is monk-log
47-
level: // Choose a log level, default il DEBUG, possible level are:
48-
// "TRACE" "DEBUG" "INFO" "WARN" "ERROR"
49-
wrap: // Wrap `name` with custom identifier, default is and array of square brackets ['[', ']']
50-
}
5144
```
5245

5346
## Examples
5447

55-
see more inside `examples folder`
48+
See more inside `examples folder`
5649

50+
### Ready-to-go logging
5751
```javascript
58-
const { levels, monkLog } = require('monk-log')
59-
const log = monkLog({
60-
name: 'MONK-LOG',
61-
level: levels.DEBUG,
62-
wrap: ['+', '+']
63-
})
52+
const log = require('monk-log')
53+
log.warn('You can have nice log messages in just one line!')
6454

65-
log.debug('this is a debug log')
66-
log.info('this is an info log')
67-
log.warn('this is a warning log')
68-
log.error('this is an error log')
55+
// Outputs
56+
// [2019-02-18T01:10:49.933] WARN [root]: You can have nice log messages in just one line!
57+
```
6958

70-
// Response
71-
// [2019-02-08T18:35:40.245] INFO monk-log: Set log level to DEBUG
72-
// [2019-02-08T18:35:40.245] DEBUG +MONK-LOG+: this is a debug log
73-
// [2019-02-08T18:35:40.245] INFO +MONK-LOG+: this is an info log
74-
// [2019-02-08T18:35:40.245] WARN +MONK-LOG+: this is a warning log
75-
// [2019-02-08T18:35:40.245] ERROR +MONK-LOG+: this is an error log
59+
### Child loggers with custom format
7660

61+
```javascript
62+
const log = require('monk-log')
63+
// Default level is WARN,
64+
log.setDefaultLevel('DEBUG')
65+
const childLogger = log.getLogger('CHILD', 'DEBUG', {
66+
template: 'When: %t, who: %n, why: %l, what: '
67+
})
68+
log.info('Child logger has been set up')
69+
childLogger.debug('this is a debug message')
70+
childLogger.info('This is a info message')
71+
childLogger.warn('this is a warning message')
72+
childLogger.error('this is an error message')
73+
74+
// Outputs
75+
// [2019-02-18T01:08:46.260] INFO [root]: Child logger has been set up
76+
// When: 2019-02-18T01:08:46.262, who: CHILD, why: DEBUG, what: this is a debug message
77+
// When: 2019-02-18T01:08:46.262, who: CHILD, why: INFO, what: This is a info message
78+
// When: 2019-02-18T01:08:46.262, who: CHILD, why: WARN, what: this is a warning message
79+
// When: 2019-02-18T01:08:46.263, who: CHILD, why: ERROR, what: this is an error message
7780
```

0 commit comments

Comments
 (0)