1.0.2 • Published 8 months ago

besonders-logger v1.0.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
8 months ago

besonders-logger

Why?

Simple & powerful syntax

const { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(
    Logger.INFO, 
    { prefix: '[DB]' } // (optional)
);

DEBUG(`test=${1}`, extra, {objects})
LOG(`test=${1}`)
if (VERBOSE.isEnabled) VERBOSE(`won't be run:`, heavyComputation())
WARN(`test=${1}`, extra, {objects})
throw ERROR(`msg logged & returned as Error, plus formatted:`, extra, {objects})

... while still preserving correct log location

  • in devtools, you see the correct line as origin
  • in node.js you can print the source location in grey (optional)

(optional) Concise relative times

Screenshot (only with custom devtoolsFormatters enabled)

Installation

Add besonders-logger to a Javascript/Typescript project:

pnpm add besonders-logger
yarn add besonders-logger
npm add besonders-logger

# (optional) install vscode snippets:
# Linux script, source: .vscode/install-snippets.sh
pnpm run besonders-install-snippets
# or copy manually from the source repo

Usage

And in any file you want to use logger:

// protip: use `logsetup` snippet

import { Logger } from "@ztax/logger/src";

const { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO); // eslint-disable-line no-unused-vars

Change log-level

const { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.DEBUG); // eslint-disable-line no-unused-vars
const { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.WARN); // eslint-disable-line no-unused-vars
//... or any other level

console.groupCollapsed mdn

LOG.group('init', () => {
	LOG('do something')
	doSomething()
	DEBUG('something done')
})

The inner function will always be executed - also when the loglevel would be filtered, in which case there is no group around the inner logs.

Temporarily override loglevel for a single line

Pro tip: add a pre-commit hook to disallow committing

VERBOSE.force("foo") // will be printed in any loglevel

Temporarily log everything

window.FORCE_DISABLE_LOGLEVEL = true
1.0.2

8 months ago

1.0.1

1 year ago

1.0.0-RC15

1 year ago

1.0.0-RC14

1 year ago

1.0.0-RC17

1 year ago

1.0.0-RC16

1 year ago

1.0.0-RC13

1 year ago

1.0.0-RC12

1 year ago

1.0.0-RC11

2 years ago

1.0.0-RC10

2 years ago

1.0.0-RC9

2 years ago

1.0.0-RC8

2 years ago

1.0.0-RC7

2 years ago

1.0.0-RC6

2 years ago

1.0.0-RC5

2 years ago

1.0.0-RC4

2 years ago

1.0.0-RC3

2 years ago

1.0.0-RC2

2 years ago

1.0.0-RC1

2 years ago