npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ciklum/ng-logan

v0.2.11

Published

NGLOGAN - extended logger service for you angular 2+ app.

Downloads

3

Readme

NGLOGAN - extended logger service for you angular 2+ app.

pipeline status coverage report

Table of contents

  1. NgLogan
  2. Installation and usage
  3. Log levels
  4. Usage and API

NgLogan

NgLogan is a library for an angular application that allows to log messages to a debugging console. It helps to debug code and you can easily hide outputs in console before deploying by changing set parameters.

Installation and usage

Set private registry by adding registry=http://npm.pp.ciklum.com/ to your .npmrc file.
Install ng-logan library by running

npm i @ciklum/ng-logan

Service should be configurable from the main application

Configuration

There is opportunity to register the service for root module or for feature module using forRoot() and forChild() methods. In forRoot() method you should pass configurable config with globalTitle: string, title: string, logLevel: string and ignoreLogLevel: boolean params.

Import { NgLoganModule } from "@ciklum/ng-logan"

Add to imports:

imports: [ 
NgLoganModule.forRoot({
globarlTitle: <your_glogal_title>, 
title: <your_local_title>, 
logLevel: <log_level>,
ignoreLogLevel: <ignore_param>
}) ]
  • for root module

Add to
imports: [ NgLoganModule.forChild( )] - for feature modules

For example:

    NgLoganModule.forRoot({
      globalTitle: 'My global',
      title: 'My local title',
      logLevel: 'warn',
      ignoreLogLevel: false
    }),

Log levels

NgLoganService supports next types of logLevels:
log
debug
info
warn
error
Every logLevel has value, log and debug has the lowest value, error level has the biggest value. If you set the error logLevel in default config, then only console.error will work and other methods with lower values won't work. If you set the info logLevel in default config, only console.info, console.warn, console.error will work. Default logLevel value is debug.

Usage and API

NgLoganService

If we inject NgLoganService in a component, we get messages in console with title from config.

export class TempComponent implements OnInit {
 
  constructor(private ngLoganService: NgLoganService) { }

  ngOnInit() {
    this.ngLoganService.info('info method')
    this.ngLoganService.warn('warn method')
    this.ngLoganService.error('error method')
  }
}

Result:

// [My global : My local title] warn method
// [My global : My local title] error method

There is an opportunity to change local title for every module that will be desplayed in console messages. Also there is an opportunity to ignore config logLevel.

@Logger decorator

@Logger is a property decorator. It was created for setting local parameters and for easy usage of NgLoganService.

  @Logger() private readonly logger

Then you can use logger property to log some text.

@Logger decorator has next parameters:

title (optional)

The parameter set unique local title for a module. If it is not set, the default title from config is used.

ignoreLogLevel (optional)

If the parameter is not set, by default it is false, the output to the console depends on the logLevel from config. If the parameter is true, it allows to ignore logLevel from config, every method of console will work.

For example:
We have warn logLevel in config.
In the first example we will see the message in console, but in the other example we won't, because in it ignoreLogLevel is not added and it is false by default.

export class AppComponent implements OnInit {
  @Logger({title: 'AppModule', ignoreLogLevel: true}) private readonly logger

  constructor() {}

  ngOnInit() {
    this.logger.info('my text will be in console')
  }
}

Other example

export class NewComponent implements OnInit {
  @Logger({title: 'AppModule'}) private readonly logger 

  constructor() {}

  ngOnInit() {
    this.logger.info("my text won't be in console")
  }
}

Result:

// [My global : AppModule] my text will be in console  

@loganClass and @loganMethod

It's also possible to use NgLoganService with decorators @loganClass or @loganMethod for a class or a method.
Decorator @loganClass consoles the parameters and results of all methods of a class.

@loganMethod consoles the parameters and results of a method for which the decorator is added.
An optional parameter for these decorators is logLevel: @loganClass('error') or @loganMethod('info'). Default logLevel value is debug.

Class decorator example:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
@loganClass('warn')

export class AppComponent implements OnInit {
  @Logger({title: 'AppModule', ignoreLogLevel: true}) private readonly logger

  constructor() {}

  ngOnInit() {
    this.sayHello('Max');
    this.sayBye('Max');
  }

  sayHello(name) {
    return `Hello, ${name}`
  }
  sayBye(name) {
    return `Bye-bye, ${name}`
  }
}

Result:

// [My global : AppModule] AppComponent - sayHello - parameters:  ["Max"]   
// [My global : AppModule] AppComponent - sayHello - results:  Hello, Max     
// [My global : AppModule] AppComponent - sayBye - parameters:  ["Max"]   
// [My global : AppModule] AppComponent - sayBye - results:  Bye-bye, Max  

Method decorator example:

export class TestComponent {
  @Logger({title: 'TempModule', ignoreLogLevel: true}) private readonly logger
 
  @loganMethod('info')
  init(value) {
    return value * value
  }
}

Result:

//  [My global : TempModule] TestComponent - Init - parameters: [5]   
//  [My global : TempModule] TestComponent - Init - results: 25  

If you want to hide all messages in console, change logLevel in config to 'error'.