Function logger

  • A minimal logger plugin that logs the result of each execution step. By default, it uses the Client from Context. If a logFile is provided, it will log to that file instead.

    The logger can be enabled or disabled at any time by emitting one of the LoggerHooks events:

    • enableLogger: Turns the logger on.
    • disableLogger: Turns the logger off.
    • toggleLogger: Toggles the logger on or off.

    Parameters

    • __namedParameters: LoggerOptions = {}

    Returns {
        description?: string;
        init: (context: Context) => MaybePromise<boolean>;
        meta: LoggerMeta;
        name: string;
        version: string;
    }

    • Optionaldescription?: string
    • init: (context: Context) => MaybePromise<boolean>

      Initialize the plugin.

    • meta: LoggerMeta

      Additional metadata about the plugin that doesn't fit in the standard fields.

      Note: Plugin info on the Context object will be frozen after the plugin is initialized. However, the freeze is shallow, so the fields of this object will be mutable by default.

    • name: string
    • version: string
    import { run, logger } from 'clide-js';

    run({ plugins: [logger()] });

    import { run, logger } from 'clide-js';

    function timestamp() {
    return new Date().toISOString();
    }

    run({
    plugins: [
    logger({
    prefix: timestamp,
    logFile: `logs/${timestamp()}.log`,
    enabled: process.env.NODE_ENV === 'development',
    })
    ],
    });

    import { command, disableLogger, enableLogger } from 'clide-js';

    export default command({
    options: {
    v {
    description: 'Enable verbose logging',
    type: 'boolean',
    default: false,
    },
    },
    handler: async ({ options, context }) => {
    const verbose = await options.verbose();

    if (verbose) {
    enableLogger();
    } else {
    disableLogger();
    }

    // rest of the command...
    },
    });