Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Improve logs format

Tomas Valentac5582ff4ffd5
diff --git a/packages/cli/src/commands/sandbox/logs.ts b/packages/cli/src/commands/sandbox/logs.ts
index 836096252..894e836b5 100644
--- a/packages/cli/src/commands/sandbox/logs.ts
+++ b/packages/cli/src/commands/sandbox/logs.ts
@@ -31,7 +31,7 @@ export const logsCommand = new commander.Command('logs')
// Check if 24 hours (in milliseconds) have passed
if (elapsedTime >= maxRuntime) {
- console.log('Stopped printing logs after 24 hours.')
+ console.log('\nStopped printing logs — 24 hours have passed')
break
}
@@ -40,19 +40,23 @@ export const logsCommand = new commander.Command('logs')
listSandboxLogs({ apiKey, sandboxID, start }),
])
- if (info) {
- const sandbox = info.find(s => s.sandboxID === sandboxID)
+ const sandbox = info ? info.find(s => s.sandboxID === sandboxID) : undefined
+ const isRunning = !!sandbox
- printSandboxInfo({
- isRunning: !!sandbox,
- sandboxID: sandboxID,
- })
- }
+ printSandboxInfo({
+ isRunning: isRunning,
+ sandboxID: sandboxID,
+ })
for (const log of logs) {
printLog(log.timestamp, log.line)
}
+ if (!isRunning) {
+ console.log('\nStopped printing logs — sandbox is closed')
+ break
+ }
+
const lastLog = logs[logs.length - 1]
if (lastLog) {
start = new Date(lastLog.timestamp).getTime()
@@ -68,22 +72,26 @@ function printSandboxInfo({ sandboxID, isRunning }: {
sandboxID: string,
isRunning: boolean,
}) {
- process.stdout.write(`Logs for ${asBold(isRunning ? 'running' : 'closed')} sandbox ${asPrimary(sandboxID)}:\n\n`)
+ process.stdout.write(`\nLogs for ${asBold(isRunning ? 'running' : 'closed')} sandbox ${asPrimary(sandboxID)}:\n\n`)
}
function printLog(timestamp: string, line: string) {
const log = JSON.parse(line)
- delete log['TraceID']
+ const time = `[${new Date(timestamp).toISOString()}]`
+ const level = log['level'].toUpperCase()
+
+ delete log['traceID']
delete log['instanceID']
delete log['sandboxID']
delete log['source_type']
delete log['teamID']
delete log['source']
delete log['service']
+ delete log['envID']
+ delete log['level']
- const time = `[${timestamp}]`
- console.log(`${asTimestamp(time)} ` + util.inspect(log, { colors: true, depth: null, maxArrayLength: Infinity, sorted: true, compact: true, breakLength: Infinity }))
+ console.log(`${asTimestamp(time)} ${level} ` + util.inspect(log, { colors: true, depth: null, maxArrayLength: Infinity, sorted: true, compact: true, breakLength: Infinity }))
}
export async function listSandboxLogs({