Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mad-logs

andfaulkner8.1kMIT12.0.0TypeScript support: included

Winston-lite-esque Log lib for terminal and browser debugging, with piles of unignorable log tags and marker styles.

logging, logs, log, configuration, config, terminal, cli, debugger, browser, debug, errors, error-handling

readme


mad-logs

  • Colourful, obtrusive, Typescript-friendly logs for the browser console and NodeJS.
    • Completely isomorphic
  • As with Winston, lets you alter the amount of text shown based on current log level:
    • Automatic handling of any of the following LOG_LEVEL environment variable values:
      • silly, verbose, debug, info, warn, error, wtf
  • Factory for file-specific logging: logFactory
  • Over 45 separate styles to keep log output different from file-to-file for easier debugging

Installation

npm install --save mad-logs

...or...

yarn add mad-logs

Usage (browser, commonJS)

Import the library

// my-fun-file.ts
import {logFactory, Styles} from 'mad-logs';

Build a logger with the log factory

const log = logFactory(`my-fun-file.tsx`, Styles.angryBird);

Do some mad, mad logging!

log.silly('display me on the browser console, but only if the log level is set to "silly"');

log.verbose(
    'display me on the browser console, but only if the log level is "verbose" ' +
    'or higher (verbose or silly mode)'
);

log.info(
    'display me on the browser console, but only if the log level is "info" ' +
    'or higher (info, verbose, or silly)'
);

log.warn(
    'display me on the browser console, but only if the log level is "warn" ' +
    'or higher (warn, info, verbose, or silly)'
);

log.error(
    'display this on the browser console as an error message, but only if the ' +
    'log level is "error" or higher (error, warn, info, verbose, or silly)'
);

log.wtf(
    'Also display this on the browser console, as an error message'
);

const result =
    log.silly(
        'Log return value of myFunction(). Pass result thru & assign it to var "result"',
         myFunction()
     );
// result now contains the return value of myFunction()

Details (on above)

  • 'my-fun-file.js' is a placeholder for the name of the current file
    • This appears in each log line, as part of the "tag"
  • logMarkers.maceWindu << replace with any item in the log marker styles list (see below)
  • All log instance functions return the last value they were passed.
  • TODO let users make their own log markers

Available log "marker" styles

  • none
  • angryBird
  • aquarium
  • arrow
  • backAndForth
  • barbells
  • bracelet
  • brainwave
  • cantTouch
  • cartoonSwearing
  • checkmate
  • cult
  • dirtRoad
  • escherBarbieLego
  • farmerBrown
  • fountain
  • fresh
  • grasslands
  • hatBlock
  • hotPursuit
  • joy
  • kingRageBlock
  • lakeLouise
  • lucky
  • maceWindu
  • mechanicalAtFists
  • moProblems
  • mrsPotatoVHS
  • neverEnough
  • nightmare
  • pipeDream
  • ohMy
  • potOfGold
  • probeArcade
  • rainbowLeaf
  • rockIsDead
  • seafoamSalad
  • smokeyHatesChristmas
  • springy
  • swimmers
  • tangerines
  • theBird
  • theHeist
  • vendetta
  • xmlHell
  • zebra

Log marker usage

  • When first "constructing" the log factory, define the log marker as the second argument (as seen above)
    • if not given, it uses the logMarkers.none style

NodeJS-specific logging

  • Deprecated - please don't use it
    • This will be removed in an upcoming version of mad-logs
  • shared/root logging is now isomorphic, so it's no longer needed

changelog

12.0.0

  • Remove dependency on colors module
    • Switch to @colors/colors
  • Minor type fixes
  • Switch most (but not all) titles to cleaner "------" format, from "======" format.
  • Update package build node version to v16.16.0

11.4.0

Fix isomorphic style objects to instead act as conditional strings w different vals for node & browser.

  • Note that changes in v11.3.0 are broken until this is fixed.

11.3.0

Make all styles work with browser dark mode (add background colours to them).

Upgrade Typescript to v3.3.3. Remove yarn, replace with new npm version.

11.2.0

  • Restore broken typings on Style object

11.1.1

Add white bg to cartoonSwearing style (to work w Chrome devtools dark mode)

Fix padding in seafoamSalad theme

  • Adds left & right padding, so emoji no longer crosses green border

Working interpolation in inspector outputs (in shared module)

  • e.g. log.inspector.info
    • Doesn't show '${output}${bookend}' at the end out the output anymore
      • Interpolates correctly instead

11.1.0

Convert to use TS esModuleInterop mode

Remove transpiled output from codebase

Fix Swimmers style to work in Chrome devtools dark mode

11.0.0 [HUGE BREAKING CHANGES]

Default export now proxies to shared module - build log with:

import {logFactory, Styles} from 'mad-logs/lib/shared';
const log = logFactory(`input-util-components.tsx`, Styles.angryBird);

...instead of:

import {logFactory, madLogMarkers} from 'mad-logs';
const log = logFactory()(`input-util-components.tsx`, madLogMarkers.angryBird);

Imports no longer available:

  • madLogMarkers (replaced with Styles, but it works differently)
  • LogOpts
  • AppConf
  • MadLog (replaced with Log e.g. import {Log} from 'mad-logs';)
  • logValues
  • buildFileTag (however, node variant still has it, for now)

Shared module exports LogLevels type

Total removal of original non-isomorphic mad-log module

Styles (shared):

  • Remove braces from almost all Node log outputs
  • Style lucky background colour changed to yellow
  • New fountain style

Internal:

  • Slightly cleaner tests
  • Expanded docs
  • REPL moved to script dir
  • Cleaner code throughout

10.3.6

Fix documentation to be more IDE-friendly

10.3.4

Remove semicolon at end of file names in browser console in shared module

10.3.3 [BREAKING CHANGES]

Upgrade mad-utils to v0.62.0 Upgrade env-var-helpers to v5.0.1 (breaking change, vastly different output)

10.2.0

Remove trailing semicolons from browser styles

10.1.12

Add 'seafoamSalad' style

10.1.11

Add 'fresh' style

10.1.10

Improve cantTouch style in Node (Fix emoji spacing, add 'stop' emoji)

Fix moProblems style spacing in Node/isomorphic

Add new isomorphic/browser/node styles:

*   neverEnough 
*   ohMy

10.1.9

Add new cantTouch style

10.1.8

Added isomorphic styles:

*   xmlHell
*   cartoonSwearing
*   default (alias to 'none')

More consistent comment docs

10.1.7

Add space to end of all isomorphic styles

Ran prettier on (most) JS & TS files + general cleanups

Cleaned up index.ts

Remove & uninstall modules:

*   lodash.isfunction
*   lodash.partial

10.1.6

Added isomorphic styles:

*   barbells
*   brainwave

Improves/fixes isomorphic style:

*   moProblems (removes unneeded extra chars)

10.1.5

Improves/fixes (and adds emojis to) isomorphic styles:

*   rockIsDead

Added isomorphic styles:

*   checkmate
*   dirtRoad
*   farmerBrown
*   grasslands
*   hotPursuit

10.1.4

Improves/fixes (and adds emojis to) isomorphic styles:

*   angryBird
*   bracelet
*   cult
*   hatBlock
*   joy
*   lucky
*   rainbowLeaf
*   springy
*   tangerines
*   theBird

Remove spaces before file names for multiple styles

10.1.3

Added isomorphic styles:

*   kingRageBlock
*   lakeLouise
*   mechanicalAtFists

Improves/fixes isormophic styles:

*   aquarium
*   pipeDream
*   probeArcade
*   smokeyHatesChristmas

10.1.2

Fix "underline" wrapper for isomorphic styles

Fix "rainbow" wrapper for isomorphic styles

Add moProblems isomorphic style

Visible filename & added emojis in Node for smokeyHatesChristmas isomorphic style

10.1.1

Prettier run on shared module

Added isomorphic styles:

*   nightmare
*   pipeDream
*   zebra
*   mrsPotatoVHS

Fix potOfGold style (more readable, added 💰 emojis)

Reorganized styles (alphabetical)

Unit tests for (approximately) 15 more isomorphic styles

10.1.0

Added isomorphic styles:

*   springy
*   swimmers
*   tangerines
*   theBird
*   vendetta

Create new "rainbow" type string modifier

Change rainbowLeaf isomorphic style to use "rainbow" modifier for filename string in node

10.0.0

Tooling / build

*   Add prettier
*   Update tslint
*   Add .gitattributes
*   tsconfig - skips lib checks

Added isomorphic styles:

*   isoStyles.none
    *   For producing unstyled text (note: still wraps the file name in '[' and ']  ')
*   isoStyles.angryBird
*   isoStyles.arrow
*   isoStyles.backAndForth
*   isoStyles.escherBarbieLego
*   isoStyles.maceWindu

Default style for isomorphic export set to isoStyles.none (only when no style specified)

Breaking changes

mad-logs/lib/shared: Remove letter-named isomorphic styles from isoStyles object

*   Removed isoStyles.a
*   Removed isoStyles.b
*   ...
*   Removed isoStyles.l

9.1.2

Upgraded modules to latest:

  • lodash
  • mocha
  • nodemon
  • prettier
  • sinon
  • ts-node
  • env-var-helpers
  • @types/lodash

9.1.1

Added isomorphic styles 'kingRageBlock' and 'mrsPotatoVHS' New unit testing helper for rapidly testing browser styles