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

@o3r/logger

Package Overview
Dependencies
Maintainers
0
Versions
1703
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@o3r/logger

This module provides a bridge to target different loggers (logrocket, fullstory, smartlook) with a common interface. It is reporting the logs emitted by the different Otter Modules.

  • 11.5.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7K
decreased by-10.32%
Maintainers
0
Weekly downloads
 
Created
Source

Otter logger

Super cute Otter!

This package is an Otter Framework Module.

Description

Stable Version Bundle Size

This module provides a bridge to target different logger (logrocket, fullstory, smartlook) with a common interface.

How to install

ng add @o3r/logger

[!WARNING] This module requires @o3r/core to be installed.

Setup

The LoggerModule should be imported in the main Module of the application and an instance of a LoggerClient implementation bound through the forRoot method.

// in app.module.ts

import {LogRocketClient} from '@o3r/logger/logrocket-logger-client';
// import {SmartLookClient} from '@o3r/logger/smartlook-logger-client';
// import {FullStoryClient} from '@o3r/logger/fullstory-logger-client';
import {LoggerModule} from '@o3r/logger';

// ...

@NgModule({
  imports: [
    // ...
    LoggerModule.forRoot(
      new LogRocketClient('LogRocket appId')
      // new SmartLookClient('SmartLook key')
      // new FullStoryClient('FullStory orgId')
    )
  ]
})
export class AppModule {}

The store can also be bound to the third-party logging service by using the LoggerService.createMetaReducer() method.

// in app.module.ts

import {Action, MetaReducer, USER_PROVIDED_META_REDUCERS} from '@ngrx/store';
import {LoggerServuce} from '@o3r/logger';

// ...

export function getUserProvidedMetaReducers(logger: LoggerService): MetaReducer<any, Action>[] {
  const loggerServiceMetaReducer = logger.createMetaReducer();
  return loggerServiceMetaReducer ? [loggerServiceMetaReducer] : [];
}

// ...

@NgModule({
  providers: [
    // ...
    {provide: USER_PROVIDED_META_REDUCERS, deps: [LoggerService], useFactory: getUserProvidedMetaReducers}
  ]
})
export class AppModule {}

Advance usage

To provide complex logger client, the client can be provided via the LOGGER_CLIENT_TOKEN as following:

import {LogRocketClient} from '@o3r/logger/logrocket-logger-client';
import {LOGGER_CLIENT_TOKEN, LoggerModule} from '@o3r/logger';

// ...

@NgModule({
  imports: [
    LoggerModule
  ],
  providers: [
    { provide: LOGGER_CLIENT_TOKEN, useValue: new LogRocketClient('LogRocket appId') }
  ]
})
export class AppModule {}

Multi Client

The Logger service supports multi logger clients. This can be provided via the .forRoot() function of the LoggerModule as following:

import {LogRocketClient} from '@o3r/logger/logrocket-logger-client';
import {SmartLookClient} from '@o3r/logger/smartlook-logger-client';
import {LoggerModule} from '@o3r/logger';

// ...

@NgModule({
  imports: [
    // ...
    LoggerModule.forRoot(
      new LogRocketClient('LogRocket appId'),
      new SmartLookClient('SmartLook key')
    )
  ]
})
export class AppModule {}

Or via multi providers:

import {LogRocketClient} from '@o3r/logger/logrocket-logger-client';
import {SmartLookClient} from '@o3r/logger/smartlook-logger-client';
import {LOGGER_CLIENT_TOKEN, LoggerModule} from '@o3r/logger';

@NgModule({
  imports: [
    LoggerModule
  ],
  providers: [
    { provide: LOGGER_CLIENT_TOKEN, useValue: new LogRocketClient('LogRocket appId'), multi: true },
    { provide: LOGGER_CLIENT_TOKEN, useValue: new SmartLookClient('SmartLook key'), multi: true }
  ]
})
export class AppModule {}

How to use

The LoggerService is agnostic of the third-party services and offers an abstraction layer for the application.

It exposes a generic method that can be called directly regardless of the client used.

For instance:

// ...

import {LoggerService} from '@o3r/logger';

export class TravelerComponent {
  constructor(private loggerService: LoggerService) {}

  public ngOnInit() {
    this.loggerService.identify(emailAddress, {
      name: firstName + ' ' + lastName,
      email: emailAddress,
      ff: frequentFlyerNumber
    });
  }
}

Details

Find more information in the documentation.

Keywords

FAQs

Package last updated on 13 Dec 2024

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