项目作者: darekf77

项目描述 :
Isomorphic logger for Browser and NodeJS, ( typescript / javascript ) apps
高级语言: TypeScript
项目地址: git://github.com/darekf77/ng2-logger.git
创建时间: 2016-06-03T08:33:33Z
项目社区:https://github.com/darekf77/ng2-logger

开源协议:

下载


taon-logger (ng2-logger)

  • Part of taon.io
  • Isomorphic Logger for TypeScript and JavaScript apps.
  • Purpose:
    • usefull/elegant backend/frontend logger

You can use this logger in your apps with any
TS/JS framework.

See what is going on in your app!

Now chrome console logs are full of colors!

Modules marked

See nice server logs:

Modules marked

To install package run:

  1. npm install ng2-logger --save

First import proper version for your environment:

Nodejs server (or any taon’s lib/app):

  1. import { Log, Level } from 'ng2-logger'

or Browser:

  1. import { Log, Level } from 'ng2-logger/browser' // new javascript module: es2015 + esnext + angular ivy support

Simple use:

In your file with log:

  1. const log = Log.create('books');

or if you wanna just log errors and warnings :

  1. const log = Log.create('books', Level.ERROR, Level.WARN);

‘books’ is current class or anything inside .ts/.js file.

You can also assign static color to specific module in application (browser for now only):

  1. log.color = 'red';

After inited log you are able to start debugging:

  1. log.d('object',obj) // console.log
  2. log.er('object',obj) // console.error
  3. log.i('object',obj) // console.info
  4. log.w('object',obj) // console.warn

or

  1. log.debug('object',obj) // console.log
  2. log.error('object',obj) // console.error
  3. log.info('object',obj) // console.info
  4. log.warn('object',obj) // console.warn

Production mode


You will not see anyting in prduction mode:

// enable production mode in your app

Log.setProductionMode();

// your app code with console and ng2-logger logs

It is important to set production mode before any log messages are executed.

This will ensure that log messages that should not be seen are leaked out.

Selective debug - global settings


Optional specify what you wanna see in yours debug console.

This settings will override settings from files.

  1. Log.setProductionMode();
  2. Log.onlyModules('src:books', 'src:records', 'src:page:login');
  3. Log.onlyLevel(Level.ERROR,Level.INFO);

Specifying onlyModules as regular expression(s)


In the above example you’ll notice module:books and module:records were specified.

you might be using such syntax for namespace hierarchy etc. You may also pass in one or more regular

expression string(s) to the onlyModule function to specify a selection of modules you wish

to show, for instances those whose name begins with src:

  1. Log.onlyModules( new RegEx('^.src') );