From d8b528540b747147aedeae5e3ff20f7fe1a7cc56 Mon Sep 17 00:00:00 2001 From: patrick Date: Fri, 24 May 2024 16:26:02 -0300 Subject: [PATCH 1/2] Added: environment var LOG_JSON_SPACES with default value 2. Used to no beautify JSON on handler.ts Fix: logger.verbose was not working because default log level was info --- CONTRIBUTING.md | 1 + packages/components/src/handler.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 20c5bab6563..43065876352 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -131,6 +131,7 @@ Flowise support different environment variables to configure your instance. You | DEBUG | Print logs from components | Boolean | | | LOG_PATH | Location where log files are stored | String | `your-path/Flowise/logs` | | LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` | +| LOG_JSON_SPACES | Spaces to beautify JSON logs | | 2 | APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` | | TOOL_FUNCTION_BUILTIN_DEP | NodeJS built-in modules to be used for Tool Function | String | | | TOOL_FUNCTION_EXTERNAL_DEP | External modules to be used for Tool Function | String | | diff --git a/packages/components/src/handler.ts b/packages/components/src/handler.ts index fcdb83c887e..9be7f69ce93 100644 --- a/packages/components/src/handler.ts +++ b/packages/components/src/handler.ts @@ -14,16 +14,25 @@ import { ChainValues } from '@langchain/core/utils/types' import { AgentAction } from '@langchain/core/agents' import { LunaryHandler } from '@langchain/community/callbacks/handlers/lunary' -import { getCredentialData, getCredentialParam } from './utils' +import { getCredentialData, getCredentialParam, getEnvironmentVariable } from './utils' import { ICommonObject, INodeData } from './Interface' interface AgentRun extends Run { actions: AgentAction[] } +function tryGetJsonSpaces() { + try { + return parseInt(getEnvironmentVariable('LOG_JSON_SPACES') ?? '2') + } catch (err) { + return 2 + } +} + function tryJsonStringify(obj: unknown, fallback: string) { try { - return JSON.stringify(obj, null, 2) + var spaces = tryGetJsonSpaces() + return JSON.stringify(obj, null, spaces) } catch (err) { return fallback } @@ -49,6 +58,7 @@ export class ConsoleCallbackHandler extends BaseTracer { constructor(logger: Logger) { super() this.logger = logger + logger.level = getEnvironmentVariable('LOG_LEVEL') ?? 'info' } // utility methods From ba0b14585881ad1466e94245824bf1607df9caf8 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Wed, 29 May 2024 18:21:18 +0100 Subject: [PATCH 2/2] Update handler.ts --- packages/components/src/handler.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/components/src/handler.ts b/packages/components/src/handler.ts index 9be7f69ce93..cafea6436b2 100644 --- a/packages/components/src/handler.ts +++ b/packages/components/src/handler.ts @@ -31,8 +31,7 @@ function tryGetJsonSpaces() { function tryJsonStringify(obj: unknown, fallback: string) { try { - var spaces = tryGetJsonSpaces() - return JSON.stringify(obj, null, spaces) + return JSON.stringify(obj, null, tryGetJsonSpaces()) } catch (err) { return fallback } @@ -61,8 +60,6 @@ export class ConsoleCallbackHandler extends BaseTracer { logger.level = getEnvironmentVariable('LOG_LEVEL') ?? 'info' } - // utility methods - getParents(run: Run) { const parents: Run[] = [] let currentRun = run @@ -89,8 +86,6 @@ export class ConsoleCallbackHandler extends BaseTracer { return string } - // logging methods - onChainStart(run: Run) { const crumbs = this.getBreadcrumbs(run) this.logger.verbose(`[chain/start] [${crumbs}] Entering Chain run with input: ${tryJsonStringify(run.inputs, '[inputs]')}`)