Giter Site home page Giter Site logo

xamgore / winston-console-format Goto Github PK

View Code? Open in Web Editor NEW

This project forked from duccio/winston-console-format

0.0 1.0 0.0 2.1 MB

Winston@3 console formatter for debugging purposes using util.inspect().

License: MIT License

JavaScript 20.40% TypeScript 79.60%

winston-console-format's Introduction

Winston@3 console format

Version npm npm Downloads Dependencies Build Status Codecov Greenkeeper badge

Winston@3 console formatter for debugging purposes using util.inspect().

Demo

Install

npm install winston-console-format

Usage TypeScript

import { createLogger, format, transports } from "winston";
import { consoleFormat } from "winston-console-format";
import util from "util";

const logger = createLogger({
  level: "silly",
  format: format.combine(
    format.timestamp(),
    format.ms(),
    format.errors({ stack: true }),
    format.splat(),
    format.json()
  ),
  defaultMeta: { service: "Test" },
  transports: [
    new transports.Console({
      format: format.combine(
        format.colorize({ all: true }),
        format.padLevels(),
        consoleFormat({
          showMeta: true,
          metaStrip: ["timestamp", "service"],
          inspectOptions: {
            depth: Infinity,
            colors: true,
            maxArrayLength: Infinity,
            breakLength: 120,
            compact: Infinity
          }
        })
      )
    })
  ]
});

logger.silly("Logging initialized");
logger.debug("Debug an object", { make: "Ford", model: "Mustang", year: 1969 });
logger.verbose("Returned value", { value: util.format });
logger.info("Information", {
  options: ["Lorem ipsum", "dolor sit amet"],
  values: ["Donec augue eros, ultrices."]
});
logger.warn("Warning");
logger.error(new Error("Unexpected error"));

Usage JavaScript

const { createLogger, format, transports } = require("winston");
const { consoleFormat } = require("winston-console-format");
const util = require("util");

const logger = createLogger({
  level: "silly",
  format: format.combine(
    format.timestamp(),
    format.ms(),
    format.errors({ stack: true }),
    format.splat(),
    format.json()
  ),
  defaultMeta: { service: "Test" },
  transports: [
    new transports.Console({
      format: format.combine(
        format.colorize({ all: true }),
        format.padLevels(),
        consoleFormat({
          showMeta: true,
          metaStrip: ["timestamp", "service"],
          inspectOptions: {
            depth: Infinity,
            colors: true,
            maxArrayLength: Infinity,
            breakLength: 120,
            compact: Infinity
          }
        })
      )
    })
  ]
});

logger.silly("Logging initialized");
logger.debug("Debug an object", { make: "Ford", model: "Mustang", year: 1969 });
logger.verbose("Returned value", { value: util.format });
logger.info("Information", {
  options: ["Lorem ipsum", "dolor sit amet"],
  values: ["Donec augue eros, ultrices."]
});
logger.warn("Warning");
logger.error(new Error("Unexpected error"));

API

consoleFormat(options)

options

Configuration object.

Type: ConsoleFormatOptions

options.showMeta

Show/hide meta object(s).

Type: boolean
Default: true

options.metaStrip

Array of meta-object properties to hide.

Type: string[]
Default: []

options.inspectOptions

util.inspect() configuration object.

Type: Object
Default: Node util.inspect(object[, options])

winston-console-format's People

Contributors

duccio avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar

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.