UNPKG

@imqueue/core

Version:

Simple JSON-based messaging queue for inter service communication

155 lines (154 loc) 4.08 kB
/*! * Decorator: @profile * * I'm Queue Software Project * Copyright (C) 2025 imqueue.com <support@imqueue.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * * If you want to use this code in a closed source (commercial) project, you can * purchase a proprietary commercial license. Please contact us at * <support@imqueue.com> to get commercial licensing options. */ import 'reflect-metadata'; import { ILogger } from '.'; export declare enum LogLevel { LOG = "log", INFO = "info", WARN = "warn", ERROR = "error" } export interface ProfileDecoratorOptions { /** * Turns on/off execution time debugging */ enableDebugTime?: boolean; /** * Turns on/off arguments debugging */ enableDebugArgs?: boolean; /** * Defines log/level for logger * By default is log */ logLevel?: LogLevel; } /** * Checks if log level is set to proper value or returns default one * * @param {*} level * @return {LogLevel} */ export declare function verifyLogLevel(level: any): LogLevel; export declare const IMQ_LOG_LEVEL: LogLevel; export type AllowedTimeFormat = 'microseconds' | 'milliseconds' | 'seconds'; /** * Environment variable IMQ_LOG_TIME=[1, 0] - enables/disables profiled * timings logging * * @type {boolean} */ export declare const IMQ_LOG_TIME: boolean; /** * Environment variable IMQ_LOG_ARGS=[1, 0] - enables/disables profiled * call arguments to be logged * * @type {boolean} */ export declare const IMQ_LOG_ARGS: boolean; /** * Environment variable IMQ_LOG_TIME_FORMAT=[ * 'microseconds', * 'milliseconds', * 'seconds' * ]. Specifies profiled time logging format, by default is 'microseconds' * * @type {AllowedTimeFormat | string} */ export declare const IMQ_LOG_TIME_FORMAT: AllowedTimeFormat; export interface DebugInfoOptions { /** * Turns on/off time debugging */ debugTime: boolean; /** * Turns on/off args debugging */ debugArgs: boolean; /** * Class name */ className: string; /** * Call arguments */ args: any[]; /** * Method name */ methodName: string; /** * Execution start timestamp */ start: any; /** * Logger implementation */ logger: ILogger; /** * Log level to use for the call */ logLevel: LogLevel; } /** * Prints debug information * * @param {boolean} debugTime * @param {boolean} debugArgs * @param {string} className * @param {any[]} args * @param {string} methodName * @param {number} start * @param {ILogger} logger * @param {LogLevel} logLevel */ export declare function logDebugInfo({ debugTime, debugArgs, className, args, methodName, start, logger, logLevel, }: DebugInfoOptions): void; /** * Implements '@profile' decorator. * * @example * ~~~typescript * import { profile } from '@imqueue/core'; * * class MyClass { * * @profile(true) // forced profiling * public myMethod() { * // ... * } * * @profile() // profiling happened only depending on env DEBUG flag * private innerMethod() { * // ... * } * } * ~~~ * * @return {( * target: any, * methodName: (string), * descriptor: TypedPropertyDescriptor<(...args: any[]) => any> * ) => void} */ export declare function profile(options?: ProfileDecoratorOptions): (target: any, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => void;