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

@amplication/logging-utils

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplication/logging-utils

This library supplies a logger for Amplication Services

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

util-logging

This library was generated with Nx.

Building

Run nx build util-logging to build the library.

Running unit tests

Run nx test util-logging to execute the unit tests via Jest.

Getting started

Logging in libraries

Libraries should always log without relying on a logger framework. In order to do so, libraries should rely on the ILogger interface and any service/application will pass the proper logger class.

// library.class.ts
import { ILogger } from "@amplication/util/logging";

export class CakeFactory {
    constructor(private readonly logger: ILogger){}

    printInLog(message: string){
        this.logger.info(message)
        this.logger.error(message, new Error())
    }
}

Logging in services / applications

In your microservices, import the logger module and consume it in your root module.

// module.ts

import { Logger } from '@amplication/util/logging';

const logger = new Logger ({
  isProduction: true,
  component: "component-name",
  logLevel: LogLevel.Warn
})

const logMe = () => {
    logger.info("An info log message", { other: { value: 1 }})
    // ....
}

The minimum log level can be configured also with the LOG_LEVEL environment variable, instead of the logLevel: LogLevel.Warn, to one of the following values:

  • debug
  • info
  • warn
  • error

Testing utilsutils

A mocked provider can be used in unit tests. The following example explain how to use it

/// myservice.spec.ts

import { MockedLogger } from "@amplication/util/logging/test-utils";

//...
it('', () => {
    const target = new Service(MockedLogger);
})
//...

FAQs

Package last updated on 27 Aug 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