MCPcopy Create free account
hub / github.com/tiann/hapi / debugLargeJson

Method debugLargeJson

cli/src/ui/logger.ts:80–124  ·  view source on GitHub ↗
(
    message: string,
    object: unknown,
    maxStringLength: number = 100,
    maxArrayLength: number = 10,
  )

Source from the content-addressed store, hash-verified

78 }
79
80 debugLargeJson(
81 message: string,
82 object: unknown,
83 maxStringLength: number = 100,
84 maxArrayLength: number = 10,
85 ): void {
86 if (!process.env.DEBUG) {
87 this.debug(`In production, skipping message inspection`)
88 }
89
90 // Some of our messages are huge, but we still want to show them in the logs
91 const truncateStrings = (obj: unknown): unknown => {
92 if (typeof obj === 'string') {
93 return obj.length > maxStringLength
94 ? obj.substring(0, maxStringLength) + '... [truncated for logs]'
95 : obj
96 }
97
98 if (Array.isArray(obj)) {
99 const truncatedArray = obj.map(item => truncateStrings(item)).slice(0, maxArrayLength)
100 if (obj.length > maxArrayLength) {
101 truncatedArray.push(`... [truncated array for logs up to ${maxArrayLength} items]` as unknown)
102 }
103 return truncatedArray
104 }
105
106 if (obj && typeof obj === 'object') {
107 const result: Record<string, unknown> = {}
108 for (const [key, value] of Object.entries(obj)) {
109 if (key === 'usage') {
110 // Drop usage, not generally useful for debugging
111 continue
112 }
113 result[key] = truncateStrings(value)
114 }
115 return result
116 }
117
118 return obj
119 }
120
121 const truncatedObject = truncateStrings(object)
122 const json = JSON.stringify(truncatedObject, null, 2)
123 this.logToFile(`[${this.localTimezoneTimestamp()}]`, message, '\n', json)
124 }
125
126 info(message: string, ...args: unknown[]): void {
127 this.logToConsole('info', '', message, ...args)

Callers 7

startRunnerFunction · 0.80
onHappySessionWebhookFunction · 0.80
spawnSessionFunction · 0.80
onMessageMethod · 0.80
runClaudeFunction · 0.80
claudeRemoteFunction · 0.80

Calls 3

debugMethod · 0.95
logToFileMethod · 0.95

Tested by

no test coverage detected