MikroLog is a Lambda-oriented lightweight JSON logger.

// ES5 format
const { MikroLog } = require('mikrolog');
// ES6 format
import { MikroLog } from 'mikrolog';

const logger = MikroLog.start();

// String message
logger.log('Hello World!');

// Object message
logger.log({
Hello: 'World!',
statement: 'Objects work just as well!'
});

Properties

logBuffer: LogOutput[] = []

Methods

  • Parameters

    • message: Message
    • OptionalhttpStatusCode: number

    Returns LogOutput

    Output a DEBUG log. Message may be string or object. This will respect whatever sampling rate is currently set.

    logger.debug('My message!');
    
  • Parameters

    • input: Record<string, any>

    Returns void

    If you want a one-time root-level enrichment, you can do:

    const logger = MikroLog.start();
    logger.enrichNext({ someId: '123456789abcdefghi' });
    logger.info('Ping!'); // Enrichment is present on log
    logger.info('Ping!'); // Enrichment is no longer present

    You can also use nested objects:

    logger.enrichNext({ myObject: { myValue: 'Something here', otherValue: 'Something else' } });
    
  • Returns Promise<void>

    Flush ("send") logs to the external transport. Nothing happens if you don't have a transport or logs.

    To avoid doing this all the time and adding latency, simply run this at the end of your function invocation to send all buffered logs at once.

  • Returns boolean

    Check if MikroLog has sampled the last log. Will only return true value after having output an actual DEBUG log.

  • Parameters

    • correlationId: string

    Returns void

    Set correlation ID manually, for example for use in cross-boundary calls.

    This value will be propagated to all future logs.

  • Parameters

    • samplingPercent: number

    Returns number

    Set sampling rate of DEBUG logs.

  • Utility function to set a nested value in an object.

    Parameters

    • target: any
    • path: string[]
    • key: string
    • value: any

    Returns void

  • Parameters

    Returns void

    Set a custom transport.

    const transport = new AxiomTransport({
    auth: process.env.AXIOM_API_KEY,
    dataset: 'my_dataset'
    });
    logger.setTransport(transport);
  • Returns void

    An emergency mechanism if you absolutely need to reset the instance to its empty default state.

  • Parameters

    Returns MikroLog

    This instantiates MikroLog. In order to be able to "remember" event and context we use a singleton pattern to reuse the same logical instance.

    If the start method receives any input, that input will overwrite any existing metadata, event, and context.

    It will also, consequently, wipe the Lambda cold start state.

    If you want to "add" to these, you should instead call enrich() and pass in your additional data there.