Skip to content

Commit

Permalink
Added LOG_JSON_SPACES to control json beautify (#2483)
Browse files Browse the repository at this point in the history
* 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

* Update handler.ts

---------

Co-authored-by: patrick <patrick.alves@br.experian.com>
Co-authored-by: Henry Heng <henryheng@flowiseai.com>
  • Loading branch information
3 people authored May 29, 2024
1 parent 5d649b2 commit 2878af6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
17 changes: 11 additions & 6 deletions packages/components/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ 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)
return JSON.stringify(obj, null, tryGetJsonSpaces())
} catch (err) {
return fallback
}
Expand All @@ -49,10 +57,9 @@ export class ConsoleCallbackHandler extends BaseTracer {
constructor(logger: Logger) {
super()
this.logger = logger
logger.level = getEnvironmentVariable('LOG_LEVEL') ?? 'info'
}

// utility methods

getParents(run: Run) {
const parents: Run[] = []
let currentRun = run
Expand All @@ -79,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]')}`)
Expand Down

0 comments on commit 2878af6

Please sign in to comment.