Universal Logging for Typescript/JavaScript
Getting Started
Reference Manual
Plugins
FAQ's
v1.x
GitHub
Getting Started
Reference Manual
Plugins
FAQ's
v1.x
GitHub
  • Getting Started
    • Introduction
    • Installation
    • Migrating from v1
    • Concepts
    • Setup
    • Configuration
    • Log Annotation
    • Global Store
    • Capturing Log Data
    • Log Threading (MDC)
    • Filtering Logs
    • Tools
    • Putting It All Together

Migrating from Adze v1

If you were previously using v1.x of Adze, migration should be fairly straightforward. Only a few of the original API's changed and you should be able to resolve them for the most part with a find and replace in your project.

Here's what has changed:

  • adze(). is now just adze.
    • Calling seal returns a class with static methods as well.
  • Calling createShed is no longer required for any functionality.
    • createShed has been replaced with the setup function.
    • The global context is now named $adzeGlobal
  • Log listeners now only receive the log instance.
  • The configuration object now has a new configuration schema.
  • The Filtering and Utility functions have been removed.
  • Bundling has been removed.

WARNING

Some items may have been missed. Please open an issue if any other differences are discovered and we will get them documented.

Adze Factory Changes

adze(). is now just adze.

v1 Example

import adze from 'adze';

adze().log('This is a log.');

v2 Example

import adze from 'adze';

adze.log('This is a log.');

Sealing Changes

Calling seal returns a class with static methods as well.

v1 Example

import adze from 'adze';

const logger = adze().timestamp.seal();
logger().log('This is a log with a timestamp.');

v2 Example

import adze from 'adze';

const logger = adze.timestamp.seal();
logger.log('This is a log with a timestamp.');

Calling createShed Not Required

Calling createShed is no longer required for any functionality like labels, count, etc.

v1 Example

import adze from 'adze';

adze().label('blah').count.log('Counter log.');
adze().label('blah').count.log('Counter log.'); // <- count not increased

v2 Example

import adze from 'adze';

adze.label('blah').count.log('Counter log.');
adze.label('blah').count.log('Counter log.'); // <- count is increased

createShed replaced with setup

createShed has been replaced with the setup function.

Log listeners now only receive the log instance.

v1 Example

import adze, { createShed } from 'adze';

const shed = createShed({
  globalCfg: {
    // overrides here
  },
});

shed.addListener('*', (data, render, printed) => {
  // do stuff...
});

v2 Example

import adze, { setup } from 'adze';

const store = setup({
  // overrides here
});

store.addListener('*', (log) => {
  // do stuff...
});

Global Context is Now $adzeGlobal

The global context is now named $adzeGlobal instead of $shed.

v1 Example

import adze, { createShed } from 'adze';

const shed = createShed();
// Old context was named $shed
console.log('Context', global.$shed);

v2 Example

import adze, { setup } from 'adze';

setup();
// New context is named $adzeGlobal
console.log('Context', globalThis.$adzeGlobal);

Configuration Has New Schema

The configuration object now has a new configuration schema.

v1 Example

interface Configuration {
  logLevel?: number;
  useEmoji?: boolean;
  unstyled?: boolean;
  terminalColorFidelity?: 0 | 1 | 2 | 3;
  captureStacktrace?: boolean;
  machineReadable?: boolean;
  baseStyle?: string;
  logLevels?: LogLevels;
  customLevels?: Partial<LogLevels>;
  meta?: {
    [key: string]: unknown;
  };
  filters?: AdzeFilters;
}

v2 Example

interface UserConfiguration {
  activeLevel?: Level | number;
  cache?: boolean;
  cacheSize?: number;
  dump?: boolean;
  filters?: Filters;
  format?: string;
  formatters: Record<string, FormatterConstructor>;
  levels: Record<string, LevelConfig>;
  meta?: Record<string, any>;
  middleware?: Middleware[];
  silent?: boolean;
  showTimestamp?: boolean;
  timestampFormatter?: (date: Date) => string;
  withEmoji?: boolean;
}

type Level = 'alert' | 'error' | 'warn' | 'info' | 'fail' | 'success' | 'log' | 'debug' | 'verbose';
Edit this page
Last Updated:
Contributors: Andrew Stacy
Prev
Installation
Next
Concepts