Catalog npm
Back to packageRELEASE DETAILS

1.0.1

npm

@0xcryptomag/winston-plus

Winston@3 console format aimed to improve development UX

cli-table3consoledebugdebuggingdevformatformatterinspectplustablewinston
Published26 Aug 2024
Direct dependencies18
Transitive dependenciesNot calculated

README

Current package documentation

winston-dev-console

My personal additions to @epegzz's winston-dev-console
(based on winston-console-format)

  • adding the source of the logging statement to the log output
  • optimizing readability of each log statement through log statement separation, output colorization and arg pretty printing
  • log outputs in util.inspection format, or as tables

Demo

Real world screenshot:

Install

npm install winston @0xcryptomag/winston-plus

or

yarn add winston @0xcryptomag/winston-plus

Usage TypeScript

import { createLogger, format, transports, config } from "winston";
import winstonDevConsole from "@epegzz/winston-dev-console";
import util from "util";

let log = createLogger({
  levels: config.syslog.levels,
  level: "debug", // or use process.env.LOG_LEVEL
});

// Note: You probably only want to use winstonDevConsole during development
log = winstonDevConsole.init(log);
log.add(
  winstonDevConsole.transport({
    showTimestamps: false,
    addLineSeparation: true,
    logLevels: config.syslog.levels
  })
);

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

Usage JavaScript

const { createLogger, format, transports, config } = require("winston");
const winstonDevConsole = require("@epegzz/winston-dev-console").default;
const util = require("util");

let log = createLogger({
  levels: config.syslog.levels,
  level: "debug", // or use process.env.LOG_LEVEL
});

// Note: You probably only want to use winstonDevConsole during development
log = winstonDevConsole.init(log);
log.add(
  winstonDevConsole.transport({
    showTimestamps: false,
    addLineSeparation: true,
    logLevels: config.cli.levels,
  })
);

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

Usage Tables

let tableLog = createLogger({
  level: "debug", // or use process.env.LOG_LEVEL
  levels: config.syslog.levels
});

// Note: You probably only want to use winstonDevConsole during development
tableLog = winstonDevConsole.init(tableLog);
tableLog.add(
  winstonDevConsole.transport({
    showTimestamps: true,
    addLineSeparation: true,
    logLevels: config.syslog.levels,
    table: true
  })
);

// The first item of the array is reserved for the Table constructor argument which takes in an options object
// {}, [], '', or null can be used to forego a header/formatting
tableLog.info("Horizontal Table", [
    {head: ['TH 1 label', 'TH 2 label'], colWidths: [25, 25]},
    ['First value', 'Second value'],
    ['First value', 'Second value']
]);
tableLog.notice("Vertical Table", [
    {},
    { 'Some key': 'Some value' },
    { 'Another key': 'Another value' }
]);
tableLog.debug("Cross Table", [
    { head: [ '', 'Top Header 1', 'Top Header 2' ] },
    { 'Left Header 1': [ 'Value Row 1 Col 1', 'Value Row 1 Col 2' ] },
    { 'Left Header 2': [ 'Value Row 2 Col 1', 'Value Row 2 Col 2' ] }
]);

API

winstonDevConsole.format(options)

options

Configuration object.

Type: DevConsoleFormatOptions

options.inspectOptions

util.inspect() configuration object.

Type: Object

options.basePath

Used to remove the base path of the project when showing the file path of the log statement. By default anything in the path before (and including) the src folder will be removed.

Type: String

options.addLineSeparation

Wheather or not to separate each log statement with a blank line.

Type: Boolean
Default: true

options.showTimestamps

Wheather or not to show timestamps
During development the timestamps are usually more noise then helpful, therefore disabled by default.

Type: Boolean
Default: false

options.logLevels

Used to select the log level severity schema from the three options provided by triple-beam: npm, syslog, and cli
By default this is set to npm log levels

Type: {[k: string]: number}
Default: winston.config.npm.levels

options.showMeta

Wheather or not to show meta after the message, callee path, and optional timestamp

Type: boolean
Default: true

options.table

Wheather or not the meta lines after the message is outputted as a table rather than a string literal of an object
Use only when the output is expected to always be tablature. A second logger may be required for tables and non tables

Type: boolean Default: false

Acknowledgements

This is a fork of @epegzz's winston-dev-console

His project based off of @duccio's winston-console-format

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 18

Native requirements
18 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
colors
Environment
{
  "local_name": "colors",
  "alias": false,
  "peer_metadata": null
}
^1.4.0runtime
dotenv
Environment
{
  "local_name": "dotenv",
  "alias": false,
  "peer_metadata": null
}
^16.4.5runtime
logform
Environment
{
  "local_name": "logform",
  "alias": false,
  "peer_metadata": null
}
^2.3.0runtime
cli-table3
Environment
{
  "local_name": "cli-table3",
  "alias": false,
  "peer_metadata": null
}
0.6.5runtime
triple-beam
Environment
{
  "local_name": "triple-beam",
  "alias": false,
  "peer_metadata": null
}
^1.3.0runtime
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^7.22.0development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
2.2.1development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.2.3development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^14.14.37development
@types/logform
Environment
{
  "local_name": "@types/logform",
  "alias": false,
  "peer_metadata": null
}
^1.10.1development
@types/triple-beam
Environment
{
  "local_name": "@types/triple-beam",
  "alias": false,
  "peer_metadata": null
}
^1.3.2development
eslint-plugin-import
Environment
{
  "local_name": "eslint-plugin-import",
  "alias": false,
  "peer_metadata": null
}
^2.22.1development
eslint-plugin-lodash
Environment
{
  "local_name": "eslint-plugin-lodash",
  "alias": false,
  "peer_metadata": null
}
^7.2.0development
eslint-config-prettier
Environment
{
  "local_name": "eslint-config-prettier",
  "alias": false,
  "peer_metadata": null
}
8.1.0development
eslint-plugin-prettier
Environment
{
  "local_name": "eslint-plugin-prettier",
  "alias": false,
  "peer_metadata": null
}
^3.3.1development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
4.19.0development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
4.19.0development
winston
Environment
{
  "local_name": "winston",
  "alias": false,
  "peer_metadata": null
}
^3.xpeer

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "0bf112fdc9150b7b3e51dab86b27d41cb46b0335",
  "tarball": "https://registry.npmjs.org/@0xcryptomag/winston-plus/-/winston-plus-1.0.1.tgz",
  "fileCount": 40,
  "integrity": "sha512-JdCcfAVcbf2EaKqUU1LMIGvLytBwWwRX2EkVeO8YalodDGzhvuvj0HV8fIoSHS9PgnMAFNxHaVcCAu/oAstvdw==",
  "signatures": [
    {
      "sig": "MEYCIQDU5gfeePcjFgl0ZgT+ayXdeNbDufNgqg/UQW1Rew06MwIhAKmZpjbLLTpDjSh/4pR+CpNBQyTgXEipqZBBa1R4RESl",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 1739677
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:04 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:931c655dc9a51db81f6be765ee040bc23ebbbdaebc0fbc9b9f9599e2a97eb264

Other collected versions

1.0.510 Dec1.0.410 Dec1.0.34 Dec1.0.228 Sept1.0.024 AugView all collected versions →