Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spaceship-std

Shared utilities for Spaceship Rust programs.

Features

  • 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 --debug flag

Usage

# 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!");
}

Logging

All Spaceship programs read log levels from ~/Workspace/logging.toml:

[levels]
default = "info"
moo = "debug"
babel = "info"
richmon = "trace"

Output Sinks

  • journald: Always enabled - view with journalctl -t {component}
  • stderr: Enabled when running interactively (TTY detected) or with --debug

Hot-Reload

Send SIGHUP to reload log levels without restart:

pkill -HUP moo

Precedence

  1. --debug flag (forces debug level)
  2. global in config (overrides everything when set)
  3. Component-specific level
  4. default level
  5. Hardcoded "info"

Modules

logging

// 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);

format

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=true field) are underlined

buffered

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

Why SIGHUP?

  • 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

Dependencies

Releases

Packages

Contributors

Languages