Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fullerstack/ngx-logger

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fullerstack/ngx-logger

A Logger Utility Library for Angular

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@fullerstack/ngx-logger

A simple logger module for Angular applications

status-image version-image coverage-image download-image

Overview

Description

Proper logging of events is one of the most important aspect of any proper software design and architecture. This is to toggle a flag and have a desired portion of the logic log their activities. This is a MUST during debugging sessions, or simply to report an error and send the log on production deployments.

@fullerstack/ngx-logger attempts to streamline the logging of your application, while promoting DRY DRY.

How to install

npm i @fullerstack/ngx-logger |OR| yarn add @fullerstack/ngx-logger

How to use

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

import {
  ApplicationCfg,
  TargetPlatform,
  HttpMethod,
} from '@fullerstack/ngx-cfg';

import { LogLevels } from '@fullerstack/ngx-logger';

export const environment: Readonly<ApplicationCfg> = {
  production: false,
  // one or more app specific field(s)
  logger: {
    // Log level, (default = none)
    // Anything above `info` will be logged, anything below will be skipped
    level: LogLevels.info,
  },
};
// In your app.module.ts

import { CfgModule } from '@fullerstack/ngx-cfg';
import { LoggerModule } from '@fullerstack/ngx-logger';
import { environment } from '../environments/environment';

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

import { Component } from '@angular/core';
import { CfgService } from '@fullerstack/ngx-cfg';
import { LoggerService } from '@fullerstack/ngx-logger';

@Component({
  selector: 'app-root',
})
export class AppComponent {
  title = 'FullerStack';
  private _options: Readonly<ApplicationCfg>;

  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');
    this.log.trace('Logging trace and above');
  }

  get options(): Readonly<ApplicationCfg> {
    return this._options;
  }
}

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 ...

Note:

  1. @fullerstack/ngx-logger depends on @fullerstack/ngx-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. @fullerstack/ngx-logger should be imported at the root level of your application.
  4. To disable the logger, set the level to LogLevels.none, (default).

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

Keywords

FAQs

Package last updated on 30 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc