Shared utilities for Spaceship Rust programs.
- Centralized logging with journald sink and SIGHUP hot-reload
- SpaceshipFormat custom tracing formatter with syntax highlighting
- BufferedLayer for TUI apps that need deferred log output
- LoggingArgs clap integration for
--debugflag
# Cargo.toml
[dependencies]
spaceship-std = { path = "../../Lib/spaceship-std" }
tracing = "0.1"use clap::Parser;
use spaceship_std::logging::LoggingArgs;
#[derive(Parser)]
struct Cli {
#[command(flatten)]
logging: LoggingArgs,
#[command(subcommand)]
command: Commands,
}
fn main() {
let cli = Cli::parse();
spaceship_std::logging::init_simple("myapp", &cli.logging);
tracing::info!("Started!");
}All Spaceship programs read log levels from ~/Workspace/logging.toml:
[levels]
default = "info"
moo = "debug"
babel = "info"
richmon = "trace"- journald: Always enabled - view with
journalctl -t {component} - stderr: Enabled when running interactively (TTY detected) or with
--debug
Send SIGHUP to reload log levels without restart:
pkill -HUP moo--debugflag (forces debug level)globalin config (overrides everything when set)- Component-specific level
defaultlevel- Hardcoded "info"
// Standard init - journald + optional stderr
spaceship_std::logging::init("babel", "claude_babel", &cli.logging);
// Simple init when component name matches crate name
spaceship_std::logging::init_simple("moo", &cli.logging);
// TUI init - buffers stderr output until guard drops
let _guard = spaceship_std::logging::init_tui("voohoo", "voohoo", &cli.logging);Custom tracing formatter with syntax highlighting:
- Log levels: DEBUG=blue, INFO=green, WARN=yellow, ERROR=red
- Field names in cyan, strings in green, numbers in yellow
- File paths in magenta
- Commands (with
cmd=truefield) are underlined
For TUI applications that can't write to stderr during operation:
let _guard = spaceship_std::logging::init_tui("myapp", "myapp", &cli.logging);
// ... run TUI ...
// When _guard drops, all buffered logs flush to stderr- Unix standard: SIGHUP = "reload config" is universally understood
- No file watching overhead: Single signal vs continuous inotify polling
- Instant: ~10μs signal delivery
- Process isolation: Each component handles its own reload
- tracing - Structured logging
- tracing-subscriber - Log filtering and formatting
- tracing-journald - systemd journal sink
- signal-hook - SIGHUP handling