File size: 1,323 Bytes
61d39e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Logging in Services

# NOTE: You can, and maybe should, just use console log methods, as they are overriden to log through our logger

Services all have a logger available at `this.log`.

```javascript

class MyService extends BaseService {

    async init () {

        this.log.info('Hello, Logger!');

    }

}

```

There are multiple "log levels", similar to `logrus` or other common logging
libraries.

```javascript

class MyService extends BaseService {

    async init () {

        this.log.info('I\'m just a regular log.');

        this.log.debug('I\'m only for developers.');

        this.log.warn('It is statistically unlikely I will be awknowledged.');

        this.log.error('Something is broken! Pay attention!');

        this.log.noticeme('This will be noticed, unlike warnings. Use sparingly.');

        this.log.system('I am a system event, like shutdown.');

        this.log.tick('A periodic behavior like cache pruning is occurring.');

    }

}

```

Log methods can take a second parameter, an object specifying fields.

```javascript



class MyService extends BaseService {

    async init () {

        this.log.info('I have fields!', {

            why: "why not",

            random_number: 1, // chosen by coin toss, guarenteed to be random

        });

    }

}

```