-
Notifications
You must be signed in to change notification settings - Fork 8
feat: unify devnet logging with offckb logs and a quiet foreground node #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@offckb/cli': minor | ||
| --- | ||
|
|
||
| Unify devnet logging around the node's log files and add `offckb logs`. A foreground `offckb node` no longer relays the raw node/miner stdout: the console now shows lifecycle events, live contract script debug output (`debug!` in scripts, streamed over the node's TCP log subscription), submitted transaction hashes, and RPC errors — the full node log stays in `data/logs/run.log` as always, and `--verbose` restores the old firehose. The new `offckb logs [node|script|miner|rpc] [-f] [--grep] [--tail]` command reads those log files (`docker logs` style), so logs are reachable in every run mode — foreground, daemon, or while `offckb status` is attached — and pipe/agent friendly. The RPC proxy is quieter too: per-request lines moved from info to debug, JSON-RPC errors in responses now surface as warnings, and everything the proxy sees is appended to `data/logs/proxy.log` (viewable via `offckb logs rpc`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { | ||
| LOG_TARGETS, | ||
| LogTarget, | ||
| SCRIPT_LOG_TARGET, | ||
| filterLinesByTarget, | ||
| followLogFile, | ||
| grepLines, | ||
| parseCkbLogLine, | ||
| readLogTail, | ||
| resolveLogPath, | ||
| } from '../devnet/log-file'; | ||
| import { readSettings, Settings } from '../cfg/setting'; | ||
| import { logger as defaultLogger, UnifiedLogger } from '../util/logger'; | ||
|
|
||
| export interface LogsOptions { | ||
| follow?: boolean; | ||
| grep?: string; | ||
| tail?: number; | ||
| } | ||
|
|
||
| const DEFAULT_TAIL = 100; | ||
|
|
||
| /** | ||
| * Print (and optionally follow) a devnet log file. The core is synchronous so | ||
| * it can be unit tested with temp files; --follow hands control to | ||
| * followLogFile and keeps the process alive until Ctrl-C. | ||
| */ | ||
| export function showLogs(target: LogTarget, options: LogsOptions, settings: Settings, logger: UnifiedLogger): void { | ||
| const filePath = resolveLogPath(target, settings); | ||
| const tail = options.tail ?? DEFAULT_TAIL; | ||
|
|
||
| let lines = readLogTail(filePath, tail); | ||
| const scriptOnly = target === 'script'; | ||
| if (scriptOnly) lines = filterLinesByTarget(lines, SCRIPT_LOG_TARGET); | ||
| if (options.grep) lines = grepLines(lines, options.grep); | ||
| for (const line of lines) logger.info(line); | ||
|
|
||
| if (!options.follow) return; | ||
|
|
||
| let inScriptEntry = false; | ||
| followLogFile(filePath, (line) => { | ||
| let show = true; | ||
| if (scriptOnly) { | ||
| // Unparsable lines are continuations of the previous entry. | ||
| const parsed = parseCkbLogLine(line); | ||
| if (parsed) inScriptEntry = parsed.target === SCRIPT_LOG_TARGET; | ||
| show = inScriptEntry; | ||
| } | ||
| if (show && options.grep && !line.includes(options.grep)) show = false; | ||
| if (show) logger.info(line); | ||
| }); | ||
| } | ||
|
|
||
| export function logsCommand(target: string | undefined, options: LogsOptions): void { | ||
| const resolved: LogTarget = LOG_TARGETS.includes(target as LogTarget) ? (target as LogTarget) : 'node'; | ||
| showLogs(resolved, options, readSettings(), defaultLogger); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.