-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add records.sh logging library package
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
layout: post | ||
title: "orbit online/records.sh" | ||
description: "A small logging library for bash. Supports `cli`, `json`, `logfmt`, and custom formats. Integrates with journald and Github actions." | ||
category: bash | ||
tags: [library, logging] | ||
--- | ||
|
||
See https://github.com/orbit-online/records.sh for the full README and more | ||
advanced use-cases. | ||
|
||
## Usage | ||
|
||
Source the script with `source "records.sh"` and log messages with the | ||
lowercased loglevel as the function name: | ||
|
||
``` | ||
debug 'Starting up.' | ||
verbose 'Startup completed' | ||
info 'Hello world!' | ||
warning 'Careful!' | ||
error 'Oh no!' | ||
``` | ||
|
||
The method signature of the logging functions mimic that of `printf`: | ||
`info FORMAT [ARGS...]`. Which means you can format variables. | ||
|
||
``` | ||
$ var=0x1f | ||
$ info "The decimal version of %s is %d" "$var" "$var" | ||
example.sh: The decimal version of 0x1f is 31 | ||
``` | ||
|
||
All log messages are output to stderr. If you want to log something to stdout | ||
simply run e.g. `info 'message' 2>&1`. | ||
|
||
## Links | ||
|
||
- [Source Code (GitHub)][https://github.com/orbit-online/records.sh] | ||
- [Author: Orbit Online A/S (Anders Ingemann)](https://orbit.online) | ||
|
||
{% include JB/setup %} |