The suite of `os::log::{info,warn,error}` were cleaned up to
support more than one message argument, which will be useufl
in logging multi-line or multi-part messages. Addditionally,
coloring was added to the severe messages. A `fatal` logging
level was added as well to facilitate the common use case of
`os::log::error; exit 1`.
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,48 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+ |
|
| 2 |
+# This file contains functions used for writing log messages |
|
| 3 |
+# to stdout and stderr from scripts while they run. |
|
| 4 |
+ |
|
| 5 |
+# os::log::info writes the message to stdout. |
|
| 6 |
+# |
|
| 7 |
+# Arguments: |
|
| 8 |
+# - all: message to write |
|
| 9 |
+function os::log::info() {
|
|
| 10 |
+ echo "[INFO] $*" |
|
| 11 |
+} |
|
| 12 |
+readonly -f os::log::info |
|
| 13 |
+ |
|
| 14 |
+# os::log::warn writes the message to stderr. |
|
| 15 |
+# A warning indicates something went wrong but |
|
| 16 |
+# not so wrong that we cannot recover. |
|
| 17 |
+# |
|
| 18 |
+# Arguments: |
|
| 19 |
+# - all: message to write |
|
| 20 |
+function os::log::warn() {
|
|
| 21 |
+ os::text::print_yellow "[WARNING] $*\n" 1>&2 |
|
| 22 |
+} |
|
| 23 |
+readonly -f os::log::warn |
|
| 24 |
+ |
|
| 25 |
+# os::log::error writes the message to stderr. |
|
| 26 |
+# An error indicates that something went wrong |
|
| 27 |
+# and we will most likely fail after this. |
|
| 28 |
+# |
|
| 29 |
+# Arguments: |
|
| 30 |
+# - all: message to write |
|
| 31 |
+function os::log::error() {
|
|
| 32 |
+ os::text::print_red "[ERROR] $*\n" 1>&2 |
|
| 33 |
+} |
|
| 34 |
+readonly -f os::log::error |
|
| 35 |
+ |
|
| 36 |
+# os::log::fatal writes the message to stderr and |
|
| 37 |
+# returns a non-zero code to force a process exit. |
|
| 38 |
+# A fatal error indicates that there is no chance |
|
| 39 |
+# of recovery. |
|
| 40 |
+# |
|
| 41 |
+# Arguments: |
|
| 42 |
+# - all: message to write |
|
| 43 |
+function os::log::fatal() {
|
|
| 44 |
+ os::text::print_red "[FATAL] $*\n" 1>&2 |
|
| 45 |
+ return 1 |
|
| 46 |
+} |
|
| 47 |
+readonly -f os::log::fatal |
|
| 0 | 48 |
\ No newline at end of file |
| ... | ... |
@@ -309,29 +309,6 @@ readonly -f disable-selinux |
| 309 | 309 |
# end of common functions for extended test group's run.sh scripts |
| 310 | 310 |
###### |
| 311 | 311 |
|
| 312 |
-function os::log::with-severity() {
|
|
| 313 |
- local msg=$1 |
|
| 314 |
- local severity=$2 |
|
| 315 |
- |
|
| 316 |
- echo "[$2] ${1}"
|
|
| 317 |
-} |
|
| 318 |
-readonly -f os::log::with-severity |
|
| 319 |
- |
|
| 320 |
-function os::log::info() {
|
|
| 321 |
- os::log::with-severity "${1}" "INFO"
|
|
| 322 |
-} |
|
| 323 |
-readonly -f os::log::info |
|
| 324 |
- |
|
| 325 |
-function os::log::warn() {
|
|
| 326 |
- os::log::with-severity "${1}" "WARNING" 1>&2
|
|
| 327 |
-} |
|
| 328 |
-readonly -f os::log::warn |
|
| 329 |
- |
|
| 330 |
-function os::log::error() {
|
|
| 331 |
- os::log::with-severity "${1}" "ERROR" 1>&2
|
|
| 332 |
-} |
|
| 333 |
-readonly -f os::log::error |
|
| 334 |
- |
|
| 335 | 312 |
function find_files() {
|
| 336 | 313 |
find . -not \( \ |
| 337 | 314 |
\( \ |