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

@ng-log/log4a

v4.0.4

Published

A powerful and customizable logging library for Angular application.

Downloads

38

Readme

npm version

Build Status

Log4A : Logger library for Angular 15+

A powerful and customizable logging library for Angular application.

New Features!

  • Pretty print log messages with timestamp, file name, method name, line number, path or call stack.
  • Support user-defined logging levels.
  • Support console, local-storage and server-side appenders.
  • Support file based configuration(logging-config.json).
  • Support runtime configuration through query param.
  • GUI supports for enable/disable logs, timestamp, setting user-defind log level at runtime.

Installation

Install the dependencies and devDependencies and start the server.

Prerequisite

-HttpClientModule
-rxjs latest
$ npm install @ng-log/log4a

Configuration

  • FileBased Configuration
  • Runtime Configuration

Setup for both File based and Runtime configuration.

Step1:

Create a json file in "assets/logging-config.json" location with below format.

[
  {
    "appenderName": "console",
    "location": "",
    "enable":  true
  },
  {
    "appenderName": "localstorage",
    "location": "logging",
    "enable": false
  },
  {
    "appenderName": "serverapi",
    "location": "/api/log",
    "enable": false
  }
] 

Step2:

Add HttpClientModule, Log4aModule, Log4a and AppenderService


/*Should add APP_INITIALIZER, HttpClientModule, Log4a libraries provided below */
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { Log4aModule, AppenderService, Log4a } from '@ng-log/log4a';

@NgModule({
  declarations: [AppComponent, ChildComponent],
  imports: [HttpClientModule, Log4aModule, BrowserModule],
  providers: [
    AppenderService,
    Log4a,
    {
      provide: APP_INITIALIZER,
      useFactory: (config: Log4a) => () => config.loadConfigs(),
      deps: [Log4a],
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Final step :

You can inject Log4a service to avail logger service.

    constructor(public logger: Log4A) {
	/*you can pass any data type like String, Object type and Arrays */
        this.logger.log('Hello Angular');
    }

And you will see the message in the console of browser:

you will see the message in the Local storage area of browser:

Support user-defined logging levels.

       this.logger.debug("debug logs");
       this.logger.warn("warn logs");
       this.logger.error("error logs");
       this.logger.info("info logs");
       this.logger.log("logs");

Support Multi Logging system in FileBased Configuration.

Inspired from java log4j; API provides three appenders.

Console Appender - Console appender is a very simple service that displays logs data to the console window. Local Storage Appender - It can store data locally with in the user’s browsers. Server logs - A server logs can store the log information from all clients in one location.

you can configure one or more appenders by setting the below flag as true.

{
"appenderName": "console",
"location": "",/*Leave it as empty; should not change this value*/
"enable":  true /*You can enable/disable this flag to use the log system*/
},
{
"appenderName": "localstorage",
"location": "logging",/*By default location name is logging; location property is customizable*/
"enable": false
},
{
"appenderName": "serverapi",
"location": "/api/log", /*By default location name is '/api/log'; location property is customizable*/
"enable": false
}

Runtime Configuration

  • You can configure the logger via query parameter.
  • Support changing the logger system on runtime, no need to restart the server,
    Console Appender : 
    http://<apphost>:<port>/?logger-option=console
    Local Storage Appender :
    http://<apphost>:<port>/?logger-option=localstorage
    Server log Appender :
    http://<apphost>:<port>/?logger-option=webapi

Note: If you are not passing any query param it will take configuration from logging-config.json file

UI component for Managing Logs

  • Enable/Disable Logs through UI.
  • Enable/Disable Timestamp.
  • Setting User-defined log levels.

Setup of UI Components

import { Log4aModule} from '@ng-log/log4a';
/**use below selector to use log ui components:**/
<log-config></log-config>

you can use user interface to enable/disable logs, setting Log levels

Errors and Solutions

main.ts:12 NullInjectorError: R3InjectorError[ApplicationModule -> ApplicationRef -> ApplicationInitStatus -> InjectionToken Application Initializer -> [object Object] -> Log4a -> AppenderService -> HttpClient -> HttpClient -> HttpClient]: NullInjectorError: No provider for HttpClient!

Solutions : Please import HttpClient Module in your Appmodule / Bootstrap Module.