Skip to main content

Crate logbook

Crate logbook 

Source
Expand description

§logbook

Core library for the logbook CLI. The binary in src/main.rs is a thin wrapper around the pure functions and types defined here, which lets the integration suite exercise the parser, error paths, and atomic-write logic directly without shelling out.

Most consumers should use the CLI; this library is exposed so that tooling (test suites, downstream integrations, alternative front-ends like a web viewer) can manipulate logbook files without re-implementing the format.

§Example: append an entry to a file

use logbook::{atomic_append, init_file, render_entry_block, RenderInput, today};
use std::path::Path;

let path = Path::new("logbook.md");
init_file(path)?;

let date = today();
let block = render_entry_block(&RenderInput {
    date: &date,
    title: "switched to websockets",
    why: "polling was hammering the API",
    rejected: Some("redis pub/sub (overkill)"),
    risk: None,
    tags: &["refactor".to_string(), "perf".to_string()],
    supersedes: None,
});
atomic_append(path, &block)?;

§Example: parse an existing file

use logbook::parse_entries;

let text = "# logbook\n\n## 2026-05-16 — t\n**why:** w\n**tags:** refactor, perf\n";
let entries = parse_entries(text);
assert_eq!(entries.len(), 1);
assert_eq!(entries[0].date.as_deref(), Some("2026-05-16"));
assert_eq!(entries[0].tags, vec!["refactor", "perf"]);

Re-exports§

pub use color::colorize_block;
pub use color::should_colorize;
pub use color::ColorChoice;
pub use error::Error;
pub use error::Result;
pub use export::entries_to_json;
pub use parse::parse_entries;
pub use parse::Entry;
pub use store::atomic_append;
pub use store::init_file;
pub use store::read_text;
pub use store::render_entry_block;
pub use store::RenderInput;

Modules§

color
Terminal coloring for human-facing output.
editor
$EDITOR integration for composing an entry’s why text interactively.
error
Error types for the logbook library.
export
JSON export for logbook entries.
parse
Parser for the logbook markdown format.
store
File I/O for the logbook.

Constants§

DEFAULT_LOGBOOK_FILE
Default filename used when ENV_VAR is not set: logbook.md.
ENV_VAR
Environment variable that overrides the default logbook path.
HEADER
Markdown header written to a freshly-initialized logbook file.

Functions§

is_date_shaped
Cheap shape check for date arguments.
logbook_path
Resolve the logbook file path.
today
Today’s date in YYYY-MM-DD format, local time.