Skip to content

Commit 527b83c

Browse files
author
John Smith III
committed
Fix: Log file location option
1 parent 247c3ea commit 527b83c

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- none
1111

12+
## [1.0.4] - 2024-11-21
13+
14+
### Fixed
15+
16+
- Log file location option
17+
1218
## [1.0.3] - 2024-11-21
1319

1420
### Fixed

noirnet

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# App version and name
88
APP_NAME="NoirNet"
9-
VERSION=1.0.3
9+
VERSION=1.0.4
1010
LAST_UPDATED="2024-11-22"
1111

1212
# Default configuration file location
@@ -196,11 +196,26 @@ log_message() {
196196

197197
# Function: Initialize the log file
198198
init_log() {
199+
if [ -z "$LOG_FILE" ]; then
200+
log_message "ERROR" "LOG_FILE variable is not set." "$LINENO"
201+
exit 1
202+
fi
203+
199204
if [ ! -f "$LOG_FILE" ]; then
200-
touch "$LOG_FILE"
201-
log_message "DEBUG" "Created log file: $LOG_FILE" "$LINENO"
205+
# Attempt to create the log file
206+
if touch "$LOG_FILE" 2>/dev/null; then
207+
log_message "DEBUG" "Created log file: $LOG_FILE" "$LINENO"
208+
else
209+
log_message "ERROR" "Failed to create log file: $LOG_FILE" "$LINENO"
210+
exit 1
211+
fi
202212
else
203-
log_message "DEBUG" "Log file already exists: $LOG_FILE" "$LINENO"
213+
# Check if the log file is writable
214+
if [ ! -w "$LOG_FILE" ]; then
215+
log_message "ERROR" "Log file exists but is not writable: $LOG_FILE" "$LINENO"
216+
exit 1
217+
fi
218+
log_message "DEBUG" "Log file already exists and is writable: $LOG_FILE" "$LINENO"
204219
fi
205220
}
206221

@@ -276,28 +291,28 @@ delete_cache() {
276291

277292
# Ensure CACHE_DIR is defined and not empty
278293
if [[ -z "$CACHE_DIR" ]]; then
279-
printf "Error: CACHE_DIR is not set. Unable to proceed.\n" >&2
294+
log_message "ERROR" "CACHE_DIR is not set. Unable to proceed." "$LINENO"
280295
exit 1
281296
fi
282297

283298
# Ensure CACHE_DIR exists
284299
if [[ ! -d "$CACHE_DIR" ]]; then
285-
printf "Error: Cache directory '%s' does not exist.\n" "$CACHE_DIR" >&2
300+
log_message "ERROR" "Cache directory '$CACHE_DIR' does not exist." "$LINENO"
286301
exit 1
287302
fi
288303

289304
# Prevent deletion of critical directories
290305
if is_critical_directory "$CACHE_DIR"; then
291-
printf "Error: Attempted to delete a critical directory '%s'. Aborting.\n" "$CACHE_DIR" >&2
306+
log_message "ERROR" "Attempted to delete a critical directory '$CACHE_DIR'. Aborting." "$LINENO"
292307
exit 1
293308
fi
294309

295310
# Attempt to delete the cache directory
296311
if rm -rf "$CACHE_DIR"; then
297-
printf "Success: All cached files in '%s' deleted.\n" "$CACHE_DIR"
312+
log_message "INFO" "Success: All cached files in '$CACHE_DIR' deleted." "$LINENO"
298313
exit 0
299314
else
300-
printf "Error: Failed to delete cached files in '%s'.\n" "$CACHE_DIR" >&2
315+
log_message "ERROR" "Failed to delete cached files in '$CACHE_DIR'." "$LINENO"
301316
exit 1
302317
fi
303318
}
@@ -911,9 +926,15 @@ process_arguments() {
911926

912927
[[ "$CLEAN" = true ]] && delete_cache
913928
init_cache
929+
930+
[[ -n "$CLI_LOG_FILE" ]] && LOG_FILE="$CLI_LOG_FILE"
914931
[[ -n "$CLI_LOG_LEVEL" ]] && LOG_LEVEL="$CLI_LOG_LEVEL"
915932
init_log
933+
934+
# Initialize CSV file
916935
init_csv
936+
937+
# Override config settings with command line options
917938
[[ "$SHOW_LOG" = true ]] && show_log
918939
[[ "$SHOW_HELP" = true ]] && show_help
919940
[[ -n "$CLI_PUSHOVER_NOTIFICATION" ]] && PUSHOVER_NOTIFICATION="$CLI_PUSHOVER_NOTIFICATION"

noirnet.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH NOIRNET 1 "November 22, 2024" "Version 1.0.3" "User Commands"
1+
.TH NOIRNET 1 "November 22, 2024" "Version 1.0.4" "User Commands"
22
.SH NAME
33
NoirNet \- Monitors internet and DNS access and sends notifications.
44

0 commit comments

Comments
 (0)