1 | ## ng2-logger ##
|
2 |
|
3 |
|
4 |
|
5 | Isomorphic Logger for TypeScript and JavaScript apps.
|
6 |
|
7 | You can use this logger in your apps with almost **any**
|
8 | TS/JS framework.
|
9 |
|
10 | See what is going on in your app!
|
11 | Now chrome console logs are full of colors!
|
12 |
|
13 | ![Modules marked](screen.png)
|
14 |
|
15 | See nice server logs:
|
16 |
|
17 | ![Modules marked](server.png)
|
18 |
|
19 |
|
20 | To install package run:
|
21 |
|
22 | npm install ng2-logger --save
|
23 |
|
24 | First import it:
|
25 |
|
26 | ```ts
|
27 | import { Log, Level } from 'ng2-logger'
|
28 | ```
|
29 |
|
30 | Simple use:
|
31 |
|
32 | Init your log :
|
33 | ```ts
|
34 | const log = Log.create('books');
|
35 | ```
|
36 | or 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 |
|
42 | You can also assign static color to specific module in application:
|
43 | ```ts
|
44 | log.color = 'red';
|
45 | ```
|
46 | After 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 |
|
58 | You 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 |
|
67 | It is important to set production mode before any log messages are executed.
|
68 | This will ensure that log messages that should not be seen are leaked out.
|
69 |
|
70 |
|
71 | **Selective debug - global settings**
|
72 | -------------------
|
73 |
|
74 | Optional specify what you wanna see in yours debug console.
|
75 | This 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 |
|
86 | In the above example you'll notice `module:books` and `module:records` were specified.
|
87 | you might be using such syntax for namespace hierarchy etc. You may also pass in one or more regular
|
88 | expression string(s) to the `onlyModule` function to specify a selection of modules you wish
|
89 | to show, for instances those whose name begins with `src`:
|
90 |
|
91 | ```ts
|
92 |
|
93 | Log.onlyModules('^src');
|
94 | ```
|
95 |
|
96 |
|