# epom-ng2-logger

A service that provides you to save and read errors, warnings, logs.

You can print all logs, print for current session (after page refresh, like F5), clear logs and turn on showing logs for all time.


### Installing

First of all you need to install module from npm

```sh
$ npm i --save epom-ng2-logger
```
### Setup
## app.component.ts
```
import ...
import ...
import {loggerCreate} from 'epom-ng2-logger/logger';            // <- inserted code

export class AppComponent {
  private logger;                                               // <- inserted code
  constructor(...) {
    this.logger = loggerCreate(this.constructor['name']);       // <- inserted code
}
...
```

### Initialization
## your.component.ts / your.service.ts
```
import ...
import ...
import {loggerCreate} from 'epom-ng2-logger/logger';           // <- inserted code

export class YourComponent {
  private logger;                                              // <- inserted code
  constructor(...) {
    this.logger = loggerCreate(this.constructor['name']);      // <- inserted code
    this.logger.log('Open Dashboard page');                    // <- inserted code, CHANGE PAGE NAME!
  }
  ...
```



## Parts
    .
    |-- epom-ng2-language-service
    |   |-- lang_en
    |   |   |-- messages.ts
    |   |   |-- ...
    |   |   |-- another-messages.ts
    |   |-- index


    this.logger.colored('Your message', 'red'); // only (String, String)
### You can also:
    this.logger.log();   // all kind of data, arrays, objects, etc
    this.logger.info();
    this.logger.warn();
    this.logger.error();

## Service public methods
| Method Declaration                                                      | Description |
| ----------------------------------------------------------------------- | ----------- |
| .**log**(any): void | save message that will be print by console.log |
| .**info**(any): string | save message that will be print by console.info |
| .**warn**(any): void | save message that will be print by console.warn |
| .**error**(any): void | save message that will be print by console.error |
| .**colored**(message: string, color: string): void | save message that will be print by console.log but with custom log color|

Examples:
```javascript
    this.logger.log(1);
this.logger.log('debug variable', debugVariable);

this.logger.warn(
  ['debug variable', debugVariable, 2], 4, {abc:'def'}
);

this.logger.colored('test', 'grey');
this.logger.colored('test 2', 'red');
this.logger.colored('test 3', 'green');
this.logger.colored('test 4', 'blue');
```

### Getting logs from DevTools
    __diagnose() // all report
    __diagnoseSession() // current session report, all logs after page reload
    __diagnoseClean()  // remove all logs from localStorage
    __diagnoseAlways() // set localStorage Flag, that always show logs

## Contributors
Mihail Andriiash <m.andriiash@itmgmedia.net>
Roman Gryadunov <g.strelets@itmgmedia.net>
