feat(params): Add log type, fmt params

Add log type and format parameters. Update defaults. Update help script.
This commit is contained in:
2026-07-24 01:03:28 -06:00
parent 1732de343d
commit c792ec8a0a
+38 -26
View File
@@ -153,34 +153,38 @@ scriptHelp() {
textBlock "The only required parameter is '--records' which is a comma-delimited list of hostnames to update. However, there are several other options which may be useful to implement."
textBlock "Parameters are listed below and followed by a description of their effect. If a default value exists, it will be listed on the following line in (parentheses)."
newline
textBlock "${magenta}--- script related parameters ---${norm}"
textBlock "${magenta}--- script-related parameters ---${norm}"
newline
textBlockSwitches "-c | --cred | --creds | --credentials | -f (deprecated, backward-compatibility)"
textBlock "Path to file containing your Cloudflare *token* credentials. Please refer to the repo README for more information on format, etc."
textBlock "Path to the file containing your Cloudflare *token* credentials. Please refer to the repo README for more information on format, etc."
textBlockDefaults "(${accountFile})"
newline
textBlockSwitches "-l | --log"
textBlock "Path where the log file should be written."
textBlockSwitches "--log-file"
textBlock "Path where the log file should be written. Script will use file-based logging."
textBlockDefaults "(${logFile})"
newline
textBlockSwitches "--nc | --no-color | --no-colour"
textBlock "Switch value. Disables ANSI colours in the log. Useful if you review the logs using a reader that does not parse ANSI colour codes."
textBlockDefaults "(disabled: print logs in colour)"
newline
textBlockSwitches "--log-console"
textBlock "Switch value. Output log to console (stdout) instead of a log file. Can be combined with --nc if desired."
textBlockDefaults "(disabled: output to log file)"
textBlock "Switch value. Script will use console-based (stdout) logging."
textBlockDefaults "(disabled: use file-based logging)"
newline
textBlockSwitches "--log-journal"
textBlock "Switch value. Output a structured log entry to your journaling system instead of a log file. Implies --nc."
textBlockDefaults "(disabled: output to log file)"
textBlock "Switch value. Script will use journald-based logging."
textBlockDefaults "(disabled: use file-based logging)"
newline
textBlockSwitches "--no-log"
textBlock "Switch value. Do not create a log (i.e. no console, no file). You will not have *any* output from the script if you choose this option, so you will not know if updates succeeded or failed."
textBlockDefaults "(disabled: output to log file)"
textBlockSwitches "--log-none"
textBlock "Switch value. Script will not log anything. You will not have *any* output from the script if you choose this option, so you will not know if updates succeed or fail."
textBlockDefaults "(disabled: use file-based logging)"
newline
textBlockSwitches "--fmt-json"
textBlock "Switch value. Use JSON formatted key-value pair structured logging format. Best when using a log parsing tool or log management system to read your log files. Does not apply when using '--log-journal'."
textBlockDefaults "(enabled)"
newline
textBlockSwitches "--fmt-syslog"
textBlock "Switch value. Use a modified syslog (plain-text) format for log messages. Ideal when logging to the console. Does not apply when using '--log-journal'."
textBlockDefaults "(disabled: use structured JSON logging)"
newline
textBlockSwitches "-h | --help | -?"
textBlock "Display this help screen."
textBlock "Display this information screen."
newline
textBlockSwitches "--examples"
textBlock "Show some usage examples."
@@ -191,7 +195,7 @@ scriptHelp() {
textBlock "Comma-delimited list of hostnames for which IP addresses should be updated in Cloudflare DNS. This parameter is REQUIRED. Note that this script will only *update* records, it will not create new ones. If you supply hostnames that are not already defined in DNS, the script will log a warning and will skip those hostnames."
newline
textBlockSwitches "-i | --ip | --ip-address | -a | --address"
textBlock "New IP address for DNS host records. If you omit this, the script will attempt to auto-detect your public IP address and use that."
textBlock "New IP address for DNS host records. If you omit this, the script will attempt to auto-detect your public IP address and use that. N.B. IP addresses are *not* parsed for correctness."
newline
textBlockSwitches "-4 | --ip4 | --ipv4"
textBlock "Switch value. Update Host 'A' records (IP4) only. Note that this script can only update either A *or* AAAA records. If you need to update both, you'll have to run the script once in IP4 mode and again in IP6 mode. If you specify both this switch and the IP6 switch, the last one specified will take effect."
@@ -227,6 +231,8 @@ scriptPath="$(CDPATH='' \cd -- "$(dirname -- "$0")" && pwd -P)"
scriptName="$(basename "$0")"
logFile="$scriptPath/${scriptName%.*}.log"
logToJournal=0
useJsonLogFmt=1
useSyslogLogFmt=0
accountFile="$scriptPath/cloudflare.credentials"
colourizeLogFile=1
dnsRecords=""
@@ -253,8 +259,8 @@ while [ $# -gt 0 ]; do
# display sample commands
scriptExamples
;;
-l | --log)
# set log file location
--log-file)
# use file-based logging at the specified location
if [ -n "$2" ]; then
logFile="${2%/}"
shift
@@ -263,23 +269,29 @@ while [ $# -gt 0 ]; do
fi
;;
--log-console)
# log to the console instead of a file
# use console-based logging
logFile="/dev/stdout"
;;
--log-journal)
# log to the journal system instead of a file
# use journald-based logging
logToJournal=1
;;
--no-log)
--log-none)
# do not log anything
logFile="/dev/null"
;;
--nc | --no-color | --no-colour)
# do not colourize log file
colourizeLogFile=0
--fmt-json)
# use JSON log formatting
useJsonLogFmt=1
useSyslogLogFmt=0
;;
--fmt-syslog)
# use modified syslog plain-text log formatting
useSyslogLogFmt=1
useJsonLogFmt=0
;;
-c | --cred* | -f)
# path to Cloudflare credentials file
# path to the Cloudflare credentials file
if [ -n "$2" ]; then
if [ -f "$2" ] && [ -s "$2" ]; then
accountFile="${2%/}"