Giter VIP home page Giter VIP logo

just-enough-logger's Introduction

just-enough-logger

Minimal logger for nodejs

Installation

npm install just-enough-logger

or

yarn add just-enough-logger

Usage

const { Logger } = require("just-enough-logger");
// or
// [DEPRECATED] const Logger = require("just-enough-logger").default;
// Default export is available for backward compatibility. It'll be removed in next version.

let log = new Logger();

// let log = new Logger(options?); // Check options

// By default, prints to a file and console
// Default file is current_directory/log.log
// Check the options for more details

log.info("this is info message");
// 10/2/2019, 12:57:14 AM : [INFO] : this is info message

log.warn("this is warn message");
// 10/2/2019, 12:57:14 AM : [WARN] : this is warn message

log.error("this is error message");
// 10/2/2019, 12:57:14 AM : [ERROR] : this is error message

Options

Pass the options object to Logger constructor.

transports

  • Where to print log message
  • Type: Array
  • Valid Values: ["file", "console"]
  • Default: ["file", "console"]

Example:

let log = new Logger({
  transports: ["console"], // Only prints on console
});

file

  • Path of log file
  • Type: Path String
  • Valid Values: /path/to/log.log
  • Default: [current_directory]/log.log

Example:

let log = new Logger({
  file: path.resolve(__dirname, "logs", "my-log.log"),
});

formatter

  • Custom formatter
  • Type: Function
  • Signature: (message: string, level: "info" | "warn" | "error") => string
  • Default: Returns log in format ${new Date().toLocaleString()} : [${level.toUpperCase()}] : ${message}

Example:

let log = new Logger({
  formatter: (message, level) => {
    return `${new Date()} ${level} ${message}`;
  },
});

Methods

Methods work on instance of Logger

getLogFilePath()

  • Returns the path of log file.
let logger = new Logger();
console.log(logger.getLogFilePath()); // c:\Programming\my-project\log.log

getLogStream()

  • Returns WriteStream of log file or null if file transports is not present.
let logger = new Logger();
console.log(logger.getLogStream());

License

MIT - @saisandeepvaddi

just-enough-logger's People

Contributors

saisandeepvaddi avatar dependabot[bot] avatar

Stargazers

Roman avatar Nirmal avatar

Watchers

James Cloos avatar  avatar

just-enough-logger's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

File: renovate.json
Error type: The renovate configuration file contains some invalid settings
Message: Invalid configuration option: pacakgeRules

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.