Git Product home page Git Product logo

logger's Introduction

logger

This package provides the logging configuration typically used in Safe Security.

Motivation

Currently in Safe Security, all the services that require logging functionality imported a library & configured it as per the service needs. Although this seems okay initially, it becomes a challenge to do this across multiple services as care needs to be taken to keep the dependency versions consistent across, code reusability takes a back seat since the configuration is duplicated everywhere, and is prone to human errors.

In order to solve this problem, the winston library used currently has been encapsulated in this package along with the desired defaults set up so that the client does not have to worry about setting up a verbose configuration in multiple files.

Installation

npm install logger-safe-security
yarn add logger-safe-security

Usage

The introduction of this package makes it very easy for clients to consume & leverage the logging capabilities.

In Javascript:

const { createLogger } = require("logger-safe-security");
const logger = createLogger({ logLevel: "info" });
logger.info("Hello world!");

In Typescript:

import { createLogger } from "logger-safe-security";
const logger = createLogger({ logLevel: "info" });
logger.info("Hello world!");

Additionally, one can pass service metadata while importing it within the context of a service. For example:

const { createLogger } = require("logger-safe-security");
const logger = createLogger({ service: "sample" });
logger.info("This log line will include service metadata");

Definition

The logger exported as part of this package contains the following definition:

  • Log format:
    • The default log format is set to JSON. Hence, all the log messages will be represented (printed) as JSON objects.
    • Timestamp will be added to all log lines in yyyy-MM-dd'T'HH:mm:ss.SSSZ format.
    • Application errors will be captured in the logs.
    • String interpolation is supported.
  • Log level:
    • The default log level is INFO.
  • Transports:
    • All logs will be written to Console by default.
    • Exceptions & Promise Rejections will be handled & written to Console as well.
  • Metadata:
    • { "type" : "application" } is added as default metadata to easily identify application logs. This can further be extended to differentiate from audit logs and add parsing/filtering rules (for e.g. in Datadog) as needed.
    • Additionally, all other metadata passed to the log messages will be stored under metadata property for easy identification & grouping.

logger's People

Contributors

prathap-safe avatar aneeshrelan avatar amanjain14 avatar semantic-release-bot avatar substancia avatar

Stargazers

xRdev38 avatar  avatar

Watchers

Kapil Mohan avatar  avatar

logger's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.