# FinlexLogger (@finlexlabs/logger)


Library Name: finlex-logger

Package Name: @finlexlabs/logger

Repo Name: fx-ng-components

## Description:
There's a lot of risk in instantiating the logger outside of angular's DI that the logger updates it's dependencies and breaks your code.

The solution is to instantiate the logger using a class that supports Angular DI, and create a singleton that your non-angular files can use.

Import logger in any of the non-angular files you can just import the instance of NGXLogger.

 

## When to use this module:

Only when the angular’s dependency is not available (e.g. model, a class outside angular, etc)

## When not to use this module:

If the ngx-logger can be imported and instantiated using the normal Angular DI (e.g. components, services, pipes that have angular DI available).


--------------------------------

Steps to Build & Publish Library

--------------------------------


## Package Renaming


Go to `./src/finlex-logger/package.json`

Rename package name from `finlex-logger` to `@finlexlabs/logger`



## Build


 `npm run build:logger`


It will build finlex-logger using ng-packagr.

The build artifacts will be stored in the `dist/` directory.



## Publishing


After building your library with `ng build:logger`, go to the dist folder `cd dist/finlex-logger` and run `npm publish`.


---
# FinlexLogger


#### app.component.ts
Instantiate the logger
```
import { NGXLogger } from 'ngx-logger';
import { initLogger, logger } from '@finlexlabs/logger';

constructor( logger: NGXLogger ) {
    initLogger(logger);
}
```

#### file.ts
Import `logger` into files where angular's DI is not available
```
import { logger } from '@finlexlabs/logger';


logger.debug("Debug message");
logger.error("error message");
logger.warn("warn message");
```