Skip to content

adoyle-h/bash-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

bash-logger

A simple bash logger utility.

TOC

Install

Just download the logger.sh to local.

Usage

Only print message to stdout: source logger.sh.

Print message to stdout and write it to a file: source logger.sh "<output-path>".

API

ENTER/EXIT

Used in script entry and final exit. Used in function entry and final exit.

ENTER "message"

printed format: [<local-date-time>][DEBUG](<ENTER-or-EXIT>) <script-or-function>: <script-path-or-function-name>

DEBUG/INFO/WARN/ERROR

Support 4 levels:

  • DEBUG
  • INFO
  • WARN
  • ERROR

Use DEBUG as example.

DEBUG "message"

printed format: [<local-date-time>][<level>](<main-or-method-name>) <message>

Example

# file: ./test/logger.sh
# import the logger script
source "<path>/logger.sh ""

function foo() {
    ENTER
    DEBUG "DEBUG message"
    INFO "INFO message"
    echo "echo message"
    WARN "WARN message"
    ERROR "ERROR message"
    EXIT
}

ENTER

foo

EXIT

It will print:

[2017/06/30 15:36:07][DEBUG](ENTER) script: ./test/logger.sh
[2017/06/30 15:36:07][DEBUG](ENTER) function: foo
[2017/06/30 15:36:07][DEBUG](foo) DEBUG message
[2017/06/30 15:36:07][INFO](foo) INFO message
echo message
[2017/06/30 15:36:07][WARN](foo) WARN message
[2017/06/30 15:36:07][ERROR](foo) ERROR message
[2017/06/30 15:36:07][DEBUG](EXIT) function: foo
[2017/06/30 15:36:07][DEBUG](EXIT) script: ./test/logger.sh

Versioning

The versioning follows the rules of SemVer 2.0.0.

Attentions: anything may have BREAKING CHANGES at ANY TIME when major version is zero (0.y.z), which is for initial development and the public API should be considered unstable.

For more information on SemVer, please visit http://semver.org/.

Copyright and License

Copyright 2017-2021 ADoyle ([email protected]). The project is licensed under the Apache License Version 2.0.

See the LICENSE file for the specific language governing permissions and limitations under the License.

See the NOTICE file distributed with this work for additional information regarding copyright ownership.