Skip to content

feat: add init_message option to suppress initialization log entry#99

Merged
GingerGraham merged 2 commits into
mainfrom
feat/optional-init-message
Apr 17, 2026
Merged

feat: add init_message option to suppress initialization log entry#99
GingerGraham merged 2 commits into
mainfrom
feat/optional-init-message

Conversation

@GingerGraham
Copy link
Copy Markdown
Owner

Issues: #98
Discussion: #97

Copilot AI review requested due to automatic review settings April 17, 2026 17:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_MESSAGE toggle, config parsing (init_message / log_init_message), and --no-init-message CLI 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.

Comment thread configuration/logging.conf.example Outdated
Comment on lines +72 to +75
# 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)
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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)

Copilot uses AI. Check for mistakes.
Comment on lines +408 to +409
assert_file_not_contains "$log_file" "Logger initialized" || return
assert_equals "false" "$LOG_INIT_MESSAGE" || return
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread logging.sh Outdated
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
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
echo "Error: Failed to write test message to log file" >&2
echo "Error: Failed to write initialization message to log file" >&2

Copilot uses AI. Check for mistakes.
@GingerGraham
Copy link
Copy Markdown
Owner Author

@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>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

@copilot apply changes based on the comments in this thread

Done in commit fef445d. Applied all three changes from the review:

  1. configuration/logging.conf.example — Rewrote the comment to say "Write the INIT message to the log file on initialization (default: true)" so it's clear true writes and false suppresses.
  2. tests/test_initialization.sh — Added assert_file_not_contains "$log_file" " INIT " to both test_no_init_message_flag and test_no_init_message_config, so the tests fail if the INIT level marker appears even if the message text changes.
  3. logging.sh — Changed "Failed to write test message to log file" → "Failed to write initialization message to log file".

@GingerGraham GingerGraham merged commit 30e2020 into main Apr 17, 2026
5 checks passed
@GingerGraham GingerGraham deleted the feat/optional-init-message branch April 17, 2026 19:04
GingerGraham pushed a commit that referenced this pull request Apr 17, 2026
## [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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants