All Projects → noemi-salaun → ng-logger

noemi-salaun / ng-logger

Licence: other
Angular logger service

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ng-logger

Golog
A high-performant Logging Foundation for Go Applications. X3 faster than the rest leveled loggers.
Stars: ✭ 208 (+220%)
Mutual labels:  log, logger
log
Aplus Framework Log Library
Stars: ✭ 14 (-78.46%)
Mutual labels:  log, logger
Go Logger
一个简单而强大的 golang 日志工具包,支持同步和异步输出到 命令行,文件, api 接口,文件支持按文件大小,文件行数,日期切分;A simple and powerful golang logging toolkit that supports synchronous and asynchronous output to the console, file, API interfaces, file support by file size, file line number, date sharding.
Stars: ✭ 152 (+133.85%)
Mutual labels:  log, logger
Serverlog
A simple, practical and innovative Node.js log library that enables you to view logs in Chrome dev tools and browser Console.
Stars: ✭ 117 (+80%)
Mutual labels:  log, logger
Acho
The Hackable Log
Stars: ✭ 189 (+190.77%)
Mutual labels:  log, logger
Easylogger
An ultra-lightweight(ROM<1.6K, RAM<0.3k), high-performance C/C++ log library. | 一款超轻量级(ROM<1.6K, RAM<0.3k)、高性能的 C/C++ 日志库
Stars: ✭ 1,968 (+2927.69%)
Mutual labels:  log, logger
Monolog Bundle
Symfony Monolog Bundle
Stars: ✭ 2,532 (+3795.38%)
Mutual labels:  log, logger
Loguru
Python logging made (stupidly) simple
Stars: ✭ 10,510 (+16069.23%)
Mutual labels:  log, logger
Logger
✔️ Simple, pretty and powerful logger for android
Stars: ✭ 13,093 (+20043.08%)
Mutual labels:  log, logger
Lajax
🚀 lajax - 前端日志解决方案。
Stars: ✭ 181 (+178.46%)
Mutual labels:  log, logger
Node Lambda Log
Basic logging mechanism for Node 6.10+ Lambda Functions
Stars: ✭ 115 (+76.92%)
Mutual labels:  log, logger
Xlog
Android logger, pretty, powerful and flexible, log to everywhere, save to file, all you want is here.
Stars: ✭ 2,468 (+3696.92%)
Mutual labels:  log, logger
Rain
Visualize vertical data inside your terminal 💦
Stars: ✭ 84 (+29.23%)
Mutual labels:  log, logger
Quicklogger
Library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Stars: ✭ 137 (+110.77%)
Mutual labels:  log, logger
Coolog
A expandable and flexible log framework for iOS. iOS一个灵活、可扩展的日志组件。
Stars: ✭ 82 (+26.15%)
Mutual labels:  log, logger
Heliumlogger
A lightweight logging framework for Swift
Stars: ✭ 169 (+160%)
Mutual labels:  log, logger
Android Filelogger
A general-purpose logging library with built-in support to save logs to file efficiently.
Stars: ✭ 70 (+7.69%)
Mutual labels:  log, logger
Logtofile
Android一个简单实用把Log日志打印到手机本地文件,可以自行取出来上传到服务器开源代码
Stars: ✭ 74 (+13.85%)
Mutual labels:  log, logger
Easy Log Handler
Human-friendly log files that make you more productive
Stars: ✭ 2,070 (+3084.62%)
Mutual labels:  log, logger
Logcat
Android 日志打印框架,在手机上可以直接看到 Logcat 日志啦
Stars: ✭ 189 (+190.77%)
Mutual labels:  log, logger

ng-logger

Build Status npm version devDependencies Status peerDependencies Status license

ng-logger is a simple Angular logger service that responds to two needs :

  • A log level system to be able to disable certain calls as needed. We do not want to see our debug trace on production.
  • A logger that keeps trace of the original log call. We do not want all our logs to be referenced in some logger.service.js all the time.

This package is compatible with Angular 12 and above, Angular AoT compiler and Angular CLI.

Installation

1 - Install the npm package.

npm install --save @nsalaun/ng-logger

2 - Import NgLoggerModule in your application and use forRoot(level: Level) to choose your log level :

import { NgModule }              from '@angular/core';
import { BrowserModule }         from '@angular/platform-browser';
import { AppComponent }          from './app.component';
import { NgLoggerModule, Level } from '@nsalaun/ng-logger';
     
@NgModule({
    imports:      [ BrowserModule, NgLoggerModule.forRoot(Level.LOG) ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ],
})
export class AppModule { } 

3 - Loading

Using SystemJS configuration

System.config({
    map: {
        '@nsalaun/ng-logger': 'node_modules/@nsalaun/ng-logger/bundles/nsalaun-ng-logger.umd.js'
    }
});

Angular-CLI

No need to set up anything, just import it in your code.

Rollup or webpack

No need to set up anything, just import it in your code.

Plain JavaScript

Include the umd bundle in your index.html:

<script src="node_modules/@nsalaun/ng-logger/bundles/nsalaun-ng-logger.umd.js"></script>

and use global nsalaun.ngLogger namespace.

AoT compilation

The library is compatible with AoT compilation. Because of the new metadata version with Angular 5, the library is not compatible with previous Angular version.

Usage

Basic Usage

Inject the Logger service anywhere you need it and use it like it's console :

@Component({})
export class MyComponent(){

    constructor(private logger: Logger){
    
        this.logger.log('Hello !', "It's working :)");
        
    }
}

The service offer a sub-list of window.console capacities :

  • Basics :

    • log(...args: any[]) - Outputs a message to the Web Console.
    • debug(...args: any[]) - Outputs a debugging message to the Web Console.
    • info(...args: any[]) - Outputs an informational message to the Web Console.
    • warn(...args: any[]) - Outputs a warning message to the Web Console.
    • error(...args: any[]) - Outputs an error message to the Web Console.
  • Groups :

    • group(groupTitle: string) - Creates a new inline group in the Web Console log.
    • groupCollapsed(groupTitle: string) - Creates a new inline group in the Web Console log that is initially collapsed.
    • groupEnd() - Exits the current inline group in the Web Console.
  • Time :

    • time(timerName: string) - Starts a timer you can use to track how long an operation takes. It works only with log Level equal or higher than DEBUG.
    • timeEnd(timerName: string) - Stops a timer that was previously started by calling Logger.time(). It works only with log Level equal or higher than DEBUG.

Using different log level on developpment or production

To set a different log level depending on environment, you can proceed as follows:

import { NgModule, isDevMode }   from '@angular/core';
import { BrowserModule }         from '@angular/platform-browser';
import { NgLoggerModule, Level } from '@nsalaun/ng-logger';
import { AppComponent }          from './app.component';

// Set different log level depending on environment.
const LOG_LEVEL = Level.LOG;
if (!isDevMode()) {
    const LOG_LEVEL = Level.ERROR;
}
 
@NgModule({
    imports     : [ BrowserModule, NgLoggerModule.forRoot(LOG_LEVEL) ],
    declarations: [ AppComponent ],
    bootstrap   : [ AppComponent ],
})
export class AppModule { } 

Please note this method is one among others. It may not suit your projects requirements/constraints

License

© 2017-2021 Noémi Salaün

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].