@nevware21/ts-debug
    Preparing search index...

    Interface IDbg

    A basic debug interface for logging debug information from you application or library

    interface IDbg {
        addProvider: (provider: IDbgProvider) => IDbgProviderCtx;
        chkLvl: (level: number) => boolean;
        cmds: IDbgCmds;
        create: (config?: string | IDbgConfig) => IDbg;
        each: (
            callback: DbgProviderCallback,
            handleError?: (provider: IDbgProvider, error: Error) => void,
        ) => void;
        log: IDbgLog;
        lvl: number;
        name: string;
        p?: IDbg;
        use: <R>(provider: IDbgProvider, callback: () => R) => R;
        usr: IDbgUsrCtx;
    }
    Index

    Properties

    addProvider: (provider: IDbgProvider) => IDbgProviderCtx

    Add the IDbgProvider to the collection of providers for this debug instance

    Type Declaration

    chkLvl: (level: number) => boolean

    Check to see if any logging at this level would be reported.

    Type Declaration

      • (level: number): boolean
      • Parameters

        • level: number

          The logging level

        Returns boolean

        true if at least one provider would cause the logging at this level to be recorded.

    cmds: IDbgCmds

    Additional commands that are available for this instance or any parent instance.

    create: (config?: string | IDbgConfig) => IDbg

    Create a new named IDbg instance which has the current instance as it's parent, any logging to this instance will also be delegated the providers of the current instance as well as any added to the new returne instance.

    Type Declaration

      • (config?: string | IDbgConfig): IDbg
      • Parameters

        • Optionalconfig: string | IDbgConfig

          Can be either a string or an IDbgConfig instance, when a string value this will be the name of the instance.

        Returns IDbg

        A new instance which can be used for providing scoped debugging

    import { createDbg, eDbgLevel, createConsoleProvider } from "@nevware21/ts-debug";

    // Create a new IDbg instance with the defaule values
    let dbg = createDbg();

    dbg.log.debug("Debug Message"); // Nothing emitted to the provider(s)
    dbg.log.error("Error Message"); // "Error Message" emitted to the provider(s)

    // Create a named IDbg instance enabling all debug logging levels
    let dbgAll = createbg({
    name: "MyTest",
    lvl: eDbgLevel.All
    });

    // The logging context sent to the providers will include the name `MyTest`
    dbgAll.log.debug("Debug Message"); // "Debug Message" emitted to the provider(s)
    dbgAll.log.error("Error Message"); // "Error Message" emitted to the provider(s)

    // If the console provider is added to the instance, then the name will be included
    // in the output.
    dbgAll.addProvider(createConsoleProvider());

    // The logging context sent to the providers will include the name `MyTest`
    // Nothing emitted to the console as the provide by default will only send Error and higher messages
    dbgAll.log.debug("Debug Message");

    // "[MyTest]: Error Message" emitted to the console(s)
    dbgAll.log.error("Error Message");
    each: (
        callback: DbgProviderCallback,
        handleError?: (provider: IDbgProvider, error: Error) => void,
    ) => void

    Call the provider for each registered provider.

    Type Declaration

      • (
            callback: DbgProviderCallback,
            handleError?: (provider: IDbgProvider, error: Error) => void,
        ): void
      • Parameters

        • callback: DbgProviderCallback

          The callback function to call with the provider

        • OptionalhandleError: (provider: IDbgProvider, error: Error) => void

          A callback function to call when an exception is thrown for a provider

        Returns void

    log: IDbgLog

    Return the logging interface to be used for logging debug messages

    lvl: number

    The maximum logging level that will be reported by this instance.

    name: string

    The name of the logger, the default logger is an empty name

    p?: IDbg

    If this debug instance is a child of a parent then this is a link to their parent instance.

    use: <R>(provider: IDbgProvider, callback: () => R) => R

    Add the provider to the collection of providers while executing the callback function, the requested provider will be removed after the cb has finished executing.

    Type Declaration

      • <R>(provider: IDbgProvider, callback: () => R): R
      • Type Parameters

        • R

        Parameters

        • provider: IDbgProvider

          The provider to add while executing the callback

        • callback: () => R

          The callback function to execute

        Returns R

        The response from the callback function

    User context values that are available for this instance or any parent instance