Coder Social home page Coder Social logo

nwx-logger's Introduction

Library was deprecated in favor of @fullerstack/ngx-logger

@nwx/logger

A simple logger module for Angular applications

How to install

npm i @nwx/logger |OR| yarn add @nwx/logger

How to use

// In your environment{prod,staging}.ts

import { AppCfg, TargetPlatform, HttpMethod } from '@nwx/cfg';

import { LogLevels } from 'pkgs/logger';

export const environment: AppCfg = {
  // app name
  appName: 'Neekware',
  // target (browser, mobile, desktop)
  target: TargetPlatform.web,
  // production, staging or development
  production: false,
  // one or more app specific field(s)
  log: {
    // Log level, (default = none)
    level: LogLevels.info
  }
};
// In your app.module.ts

import { CfgModule } from '@nwx/cfg';
import { LoggerModule } from '@nwx/logger';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, CfgModule.forRoot(environment), LoggerModule],
  bootstrap: [AppComponent]
})
export class AppModule {}
// In your app.component.ts or (some.service.ts)

import { Component } from '@angular/core';
import { CfgService } from '@nwx/cfg';
import { LoggerService } from '@nwx/logger';

@Component({
  selector: 'app-root'
})
export class AppComponent {
  title = 'Neekware';
  options = {};
  constructor(public cfg: CfgService, public log: LogService) {
    this.title = this.cfg.options.appName;
    this.log.critical('Logging critical');
    this.log.error('Logging error and above');
    this.log.warn('Logging warn and above');
    this.log.info('Logging info and above');
    this.log.debug('Logging debug and above');
  }
}

Note:

  1. @nwx/logger depends on @nwx/cfg for accessing the log level.
  2. You may want to set the log level to LogLevels.debug for development and LogLevels.warn for production.
  3. @nwx/logger should be imported at the root level of your application.
  4. To disable the logger, set the level to LogLevels.none.

Sample logs

CfgService ready ...
2018-05-17T02:47:54.184Z [DEBUG] LogService ready ...
2018-05-17T02:47:54.188Z [DEBUG] GqlService ready ...
2018-05-17T02:47:54.375Z [DEBUG] I18nService ready ... (en)
2018-05-17T02:47:54.378Z [DEBUG] UixService ready ...
2018-05-17T02:47:54.379Z [DEBUG] JwtService ready ...
2018-05-17T02:47:54.384Z [DEBUG] Token expiry ... (21 seconds)
2018-05-17T02:47:54.388Z [DEBUG] AuthService ready ... (loggedIn)
2018-05-17T02:47:54.390Z [DEBUG] UsrService ready ...
2018-05-17T02:47:54.392Z [DEBUG] Web app starting now ...
2018-05-17T02:47:54.406Z [DEBUG] LayoutService ready ...

Running the tests

To run the tests against the current environment:

npm run ci

License

Released under a (MIT) license.

Version

X.Y.Z Version

`MAJOR` version -- making incompatible API changes
`MINOR` version -- adding functionality in a backwards-compatible manner
`PATCH` version -- making backwards-compatible bug fixes

Sponsors

Neekware Inc.

nwx-logger's People

Contributors

dependabot[bot] avatar un33k avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.