UNPKG

2.19 kBMarkdownView Raw
1## ng2-logger ##
2
3
4
5Isomorphic Logger for TypeScript and JavaScript apps.
6
7You can use this logger in your apps with almost **any**
8TS/JS framework.
9
10See what is going on in your app!
11Now chrome console logs are full of colors!
12
13![Modules marked](screen.png)
14
15See nice server logs:
16
17![Modules marked](server.png)
18
19
20To install package run:
21
22 npm install ng2-logger --save
23
24First import it:
25
26```ts
27 import { Log, Level } from 'ng2-logger'
28```
29
30Simple use:
31
32Init your log :
33```ts
34 const log = Log.create('books');
35```
36or if you wanna just log errors and warnings :
37```ts
38 const log = Log.create('books', Level.ERROR, Level.WARN);
39```
40'books' is current class or anything inside *.ts file.
41
42You can also assign static color to specific module in application:
43```ts
44 log.color = 'red';
45```
46After inited **log** you are able to start debugging:
47```ts
48 log.d('object',obj) // console.log
49 log.er('object',obj) // console.error
50 log.i('object',obj) // console.info
51 log.w('object',obj) // console.warn
52```
53
54
55**Production mode**
56-------------------
57
58You will not see anyting in prduction mode:
59
60 // enable production mode in your app
61 ...
62 Log.setProductionMode();
63 ...
64 // your app code with console and ng2-logger logs
65
66
67It is important to set production mode before any log messages are executed.
68This will ensure that log messages that should not be seen are leaked out.
69
70
71**Selective debug - global settings**
72-------------------
73
74Optional specify what you wanna see in yours debug console.
75This settings will override settings from files.
76
77```ts
78 Log.setProductionMode();
79 Log.onlyModules('src:books', 'src:records', 'src:page:login');
80 Log.onlyLevel(Level.ERROR,Level.INFO);
81```
82
83**Specifying `onlyModules` as regular expression(s)**
84-------------------
85
86In the above example you'll notice `module:books` and `module:records` were specified.
87you might be using such syntax for namespace hierarchy etc. You may also pass in one or more regular
88expression string(s) to the `onlyModule` function to specify a selection of modules you wish
89to show, for instances those whose name begins with `src`:
90
91```ts
92
93 Log.onlyModules('^src');
94```
95
96