import debug from 'debug'; import { Debugger } from './types/debug/debug.types'; /** * @deprecated Please use `import { debug } from 'debug-next'`. Or, you may instantiate automatically namespaces loggers via `import { Log } from 'debug-next'`. */ export default debug; export { debug }; export type TDebugHook = (args: unknown[], loggerType: keyof typeof LogBase._hooks, isEnabled: boolean, scope: undefined | string | null, hookName: string) => void; type THookMap = { [key: string]: (isLoggerEnabled: boolean, scope: undefined | string | null, ...args: unknown[]) => void; }; type TDebuggers = 'log' | 'logWarn' | 'logDebug' | 'logVerbose' | 'logError' | 'logFatal'; type THooksObject = { [Key in TDebuggers]: THookMap; }; export declare const LogBase: { appName: string; baseDir: string; truncateDir: string[]; namespace(fileName: string): string; _isInitialized: boolean; /** * Initialize LogBase. Can only be done once. * @param appName Name of the app. This is a prefix to the namespace. E.g. appName:namespace1:namespace2 * @param baseDir Base directory of the app. This is required to diff the paths with other files to get a relative path for namespacing. */ init(appName: string, baseDir: string): any; _hooks: THooksObject; _hooksUnsafe: THooksObject; _runHooks(logger: TDebuggers, isEnabled: boolean, scope: undefined | null | string, args: unknown[]): void; /** * Hooks added will run after the logging is complete. * @param attachTo Attach hook to a logger. * @param hookName Name of hook. * @param hook Hook to run. Will be try/caught and not throw. * * @example * // To add a transportation to Datadog * import { datadogLogs } from '@datadog/browser-logs' * const datadogHook = (args, loggerType, isEnabled, scope, hookName) => { * // run only if the logger was enabled by namespace * if (isEnabled) { * * // loggerType is log/logDebug etc... * const msg = loggerType * * // scope is the function caller name * msg += ` ${scope}` * * // hookName is `datadog` in this case * msg += ` ${hookName}` * * // hookName is `datadog` in this case * datadogLogs.logger.info(msg, { info: args }) * } * } * LogBase.addHook('log', 'datadog', datadogHook) * * @example * // Adding Sentry hook * import * as Sentry from '@sentry/node' * const sentryHook = (...args) => { * if (args.length === 1 && args[0] instanceof Error) { * Sentry.captureException(args[0]) * return * } * * Sentry.captureException({ * message: 'Error!', * info: args * }) * } * LogBase.attachHook('logError', 'sentry', sentryHook) */ attachHook(attachTo: keyof THooksObject | 'all', hookName: string, hook: TDebugHook): void; /** * An unsafe version of #attachHook. Use this if you want the failure of the hook to throw. * Usage is the same as #attachHook. */ attachHookUnsafe(attachTo: keyof THooksObject | 'all', hookName: string, hook: TDebugHook): void; }; /** * A centralised logging interface that will create namespaced debugger automatically using the file structure. * @param fileName [optional] If left empty, it will Pass in `__filename`. */ export declare const Log: (fileName?: string) => { log: Debugger; logWarn: Debugger; logError: Debugger; logFatal: Debugger; logDebug: Debugger; logVerbose: Debugger; }; //# sourceMappingURL=index.d.ts.map