mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Make Logger a service (no-changelog) (#7494)
This commit is contained in:
committed by
GitHub
parent
db4e61ba24
commit
05586a900d
@@ -1,6 +1,8 @@
|
||||
export const BINARY_ENCODING = 'base64';
|
||||
export const WAIT_TIME_UNLIMITED = '3000-01-01T00:00:00.000Z';
|
||||
|
||||
export const LOG_LEVELS = ['silent', 'error', 'warn', 'info', 'debug', 'verbose'] as const;
|
||||
|
||||
export const CODE_LANGUAGES = ['javaScript', 'json', 'python'] as const;
|
||||
export const CODE_EXECUTION_MODES = ['runOnceForAllItems', 'runOnceForEachItem'] as const;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { Readable } from 'stream';
|
||||
import type { URLSearchParams } from 'url';
|
||||
|
||||
import type { AuthenticationMethod } from './Authentication';
|
||||
import type { CODE_EXECUTION_MODES, CODE_LANGUAGES } from './Constants';
|
||||
import type { CODE_EXECUTION_MODES, CODE_LANGUAGES, LOG_LEVELS } from './Constants';
|
||||
import type { IDeferredPromise } from './DeferredPromise';
|
||||
import type { ExecutionStatus } from './ExecutionStatus';
|
||||
import type { ExpressionError } from './ExpressionError';
|
||||
@@ -725,7 +725,7 @@ export interface RequestHelperFunctions {
|
||||
}
|
||||
|
||||
export interface FunctionsBase {
|
||||
logger: ILogger;
|
||||
logger: Logger;
|
||||
getCredentials(type: string, itemIndex?: number): Promise<ICredentialDataDecryptedObject>;
|
||||
getExecutionId(): string;
|
||||
getNode(): INode;
|
||||
@@ -1933,16 +1933,8 @@ export interface WorkflowTestData {
|
||||
};
|
||||
}
|
||||
|
||||
export type LogTypes = 'debug' | 'verbose' | 'info' | 'warn' | 'error';
|
||||
|
||||
export interface ILogger {
|
||||
log: (type: LogTypes, message: string, meta?: object) => void;
|
||||
debug: (message: string, meta?: object) => void;
|
||||
verbose: (message: string, meta?: object) => void;
|
||||
info: (message: string, meta?: object) => void;
|
||||
warn: (message: string, meta?: object) => void;
|
||||
error: (message: string, meta?: object) => void;
|
||||
}
|
||||
export type LogLevel = (typeof LOG_LEVELS)[number];
|
||||
export type Logger = Record<Exclude<LogLevel, 'silent'>, (message: string, meta?: object) => void>;
|
||||
|
||||
export interface IStatusCodeMessages {
|
||||
[key: string]: string;
|
||||
@@ -2209,8 +2201,6 @@ export interface IPublicApiSettings {
|
||||
};
|
||||
}
|
||||
|
||||
export type ILogLevel = 'info' | 'debug' | 'warn' | 'error' | 'verbose' | 'silent';
|
||||
|
||||
export type ExpressionEvaluatorType = 'tmpl' | 'tournament';
|
||||
|
||||
export interface IN8nUISettings {
|
||||
@@ -2261,7 +2251,7 @@ export interface IN8nUISettings {
|
||||
};
|
||||
publicApi: IPublicApiSettings;
|
||||
workflowTagsDisabled: boolean;
|
||||
logLevel: ILogLevel;
|
||||
logLevel: LogLevel;
|
||||
hiringBannerEnabled: boolean;
|
||||
templates: {
|
||||
enabled: boolean;
|
||||
|
||||
@@ -1,42 +1,16 @@
|
||||
import type { ILogger, LogTypes } from './Interfaces';
|
||||
import type { Logger } from './Interfaces';
|
||||
|
||||
let logger: ILogger | undefined;
|
||||
const noOp = () => {};
|
||||
export let error: Logger['error'] = noOp;
|
||||
export let warn: Logger['warn'] = noOp;
|
||||
export let info: Logger['info'] = noOp;
|
||||
export let debug: Logger['debug'] = noOp;
|
||||
export let verbose: Logger['verbose'] = noOp;
|
||||
|
||||
export function init<L extends ILogger>(loggerInstance: L) {
|
||||
logger = loggerInstance;
|
||||
return loggerInstance;
|
||||
}
|
||||
|
||||
export function getInstance(): ILogger {
|
||||
if (logger === undefined) {
|
||||
throw new Error('LoggerProxy not initialized');
|
||||
}
|
||||
|
||||
return logger;
|
||||
}
|
||||
|
||||
export function log(type: LogTypes, message: string, meta: object = {}) {
|
||||
getInstance().log(type, message, meta);
|
||||
}
|
||||
|
||||
// Convenience methods below
|
||||
|
||||
export function debug(message: string, meta: object = {}) {
|
||||
getInstance().debug(message, meta);
|
||||
}
|
||||
|
||||
export function info(message: string, meta: object = {}) {
|
||||
getInstance().info(message, meta);
|
||||
}
|
||||
|
||||
export function error(message: string, meta: object = {}) {
|
||||
getInstance().error(message, meta);
|
||||
}
|
||||
|
||||
export function verbose(message: string, meta: object = {}) {
|
||||
getInstance().verbose(message, meta);
|
||||
}
|
||||
|
||||
export function warn(message: string, meta: object = {}) {
|
||||
getInstance().warn(message, meta);
|
||||
}
|
||||
export const init = (logger: Logger) => {
|
||||
error = (message, meta) => logger.error(message, meta);
|
||||
warn = (message, meta) => logger.warn(message, meta);
|
||||
info = (message, meta) => logger.info(message, meta);
|
||||
debug = (message, meta) => logger.debug(message, meta);
|
||||
verbose = (message, meta) => logger.verbose(message, meta);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { IDataObject } from '../../src';
|
||||
import { Expression, Workflow } from '../../src';
|
||||
import type { IDataObject } from '@/Interfaces';
|
||||
import { Expression } from '@/Expression';
|
||||
import { Workflow } from '@/Workflow';
|
||||
import * as Helpers from '../Helpers';
|
||||
|
||||
export const TEST_TIMEZONE = 'America/New_York';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { INode } from '../src/Interfaces';
|
||||
import { NodeApiError, NodeOperationError } from '../src/NodeErrors';
|
||||
import type { INode } from '@/Interfaces';
|
||||
import { NodeApiError, NodeOperationError } from '@/NodeErrors';
|
||||
|
||||
const node: INode = {
|
||||
id: '1',
|
||||
|
||||
Reference in New Issue
Block a user