feat: add init_message option to suppress initialization log entry#99
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an init_message configuration/CLI option to suppress the one-time INIT entry that init_logger appends to a log file, addressing the “shared log file gets repeated INIT lines” use case from #98.
Changes:
- Add
LOG_INIT_MESSAGEtoggle, config parsing (init_message/log_init_message), and--no-init-messageCLI flag; conditionally skip writing the INIT entry. - Add tests covering default behavior, CLI suppression, and config-based suppression.
- Update docs, demo script, and example config to document the new option.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
logging.sh |
Introduces the new toggle + parsing/CLI flag and gates the INIT log-file write. |
tests/test_initialization.sh |
Adds coverage for default INIT behavior and suppression modes. |
docs/initialization.md |
Documents the new --no-init-message init option. |
docs/configuration.md |
Documents the new init_message config key + alias. |
demo-scripts/demo_config.sh |
Demonstrates suppressing INIT entries when sharing a log file. |
configuration/logging.conf.example |
Adds the init_message example setting and commentary. |
| # Suppress the INIT message written to the log file on initialization (default: true) | ||
| # Set to false to prevent "Logger initialized by <name>" from being appended to the log | ||
| # file on every init_logger call (useful when multiple scripts share the same log file, | ||
| # e.g. a main script and subscripts that all log to the same file) |
There was a problem hiding this comment.
The new config key is named init_message and the value true means the INIT message is written. The added comment block reads as if the setting suppresses the INIT message by default ("Suppress ... (default: true)"); please reword to reflect that true writes the INIT entry and false suppresses it.
| # Suppress the INIT message written to the log file on initialization (default: true) | |
| # Set to false to prevent "Logger initialized by <name>" from being appended to the log | |
| # file on every init_logger call (useful when multiple scripts share the same log file, | |
| # e.g. a main script and subscripts that all log to the same file) | |
| # Write the INIT message to the log file on initialization (default: true) | |
| # Set to false to suppress "Logger initialized by <name>" from being appended to the | |
| # log file on every init_logger call (useful when multiple scripts share the same log | |
| # file, e.g. a main script and subscripts that all log to the same file) |
| assert_file_not_contains "$log_file" "Logger initialized" || return | ||
| assert_equals "false" "$LOG_INIT_MESSAGE" || return |
There was a problem hiding this comment.
The suppression tests only assert that "Logger initialized" is absent. Since the feature is specifically about suppressing the INIT log entry, it would be stronger to also assert that the INIT marker/level (e.g., "INIT") is not written, so the test fails if the message text changes but the INIT entry still appears.
| local init_message | ||
| init_message=$(_format_log_message "INIT" "Logger initialized by $SCRIPT_NAME") | ||
| echo "$init_message" >> "$LOG_FILE" 2>/dev/null || { | ||
| echo "Error: Failed to write test message to log file" >&2 |
There was a problem hiding this comment.
The error message inside the log-file init write path says "Failed to write test message to log file", but this write is the initialization (INIT) entry. This makes troubleshooting confusing; please update the message (and/or hint) to refer to the initialization message instead of a test message.
| echo "Error: Failed to write test message to log file" >&2 | |
| echo "Error: Failed to write initialization message to log file" >&2 |
|
@copilot apply changes based on the comments in this thread |
- Fix config comment wording: true writes INIT entry, false suppresses it - Add INIT level assertions to suppression tests for stronger coverage - Fix error message: 'test message' -> 'initialization message' Agent-Logs-Url: https://github.com/GingerGraham/bash-logger/sessions/1dca36e2-ad49-4b62-981a-169ed205db36 Co-authored-by: GingerGraham <34165628+GingerGraham@users.noreply.github.com>
Done in commit
|
## [2.4.0](2.3.0...2.4.0) (2026-04-17) ### Documentation * add transparency about AI tool usage ([#96](#96)) ### Features * add init_message option to suppress initialization log entry ([#99](#99))
Issues: #98
Discussion: #97