Skip to content

Commit

Permalink
BREAKING CHANGE: change library name
Browse files Browse the repository at this point in the history
  • Loading branch information
ginokent committed Aug 26, 2023
1 parent 93d3f70 commit 9b84c67
Show file tree
Hide file tree
Showing 10 changed files with 731 additions and 418 deletions.
38 changes: 38 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# https://docs.github.com/ja/repositories/releasing-projects-on-github/automatically-generated-release-notes
changelog:
categories:
- title: "💥 BREAKING CHANGES"
labels:
- BREAKING CHANGE
- title: "⬆️ Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)"
labels:
- build
- dependencies
- title: "👷 Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)"
labels:
- ci
- title: "📝 Documentation only changes"
labels:
- docs
- title: "✨ A new feature"
labels:
- feat
- title: "🐛 A bug fix"
labels:
- fix
- title: "⚡️ A code change that improves performance"
labels:
- perf
- title: "♻️ A code change that neither fixes a bug nor adds a feature"
labels:
- refactor
- title: "✅ Adding missing tests or correcting existing tests"
labels:
- test
- title: "🚨 Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)"
labels:
- style
- title: "🧑‍💻 Changes to the build process or auxiliary tools and libraries such as documentation generation"
labels:
- chore
- "*"
61 changes: 61 additions & 0 deletions .github/workflows/sh-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: sh-test
# ~~~~~~~
# https://github.com/kunitsucom/ilog.go/workflows/sh-test/badge.svg
# ~~~~~~~

on:
push:
branches:
- main
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
pull_request:
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
workflow_dispatch:
inputs: {}

# NOTE: 連続で commit & push した時に最新の commit 以外のワークフローをキャンセルする
concurrency:
group: ${{ github.workflow }}-${{ github.base_ref }}-${{ github.head_ref }}-${{ github.ref }}
cancel-in-progress: true

permissions:
id-token: write
contents: read

env:
WORKDIR: .

defaults:
run:
shell: bash

jobs:
sh-test: # NOTE: for Branch protection rule `Status checks that are required.`
runs-on: ubuntu-latest # ref. https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
steps:
- uses: actions/checkout@v3
- name: DEBUG
run: |
cat <<'DEBUG_DOC'
== DEBUG =======================================================
github.ref: ${{ github.ref }}
github.event_name: ${{ github.event_name }}
-- toJSON(github.event.inputs) ---------------------------------
${{ toJSON(github.event.inputs) }}
-- toJSON(github) ----------------------------------------------
${{ toJSON(github) }}
================================================================
DEBUG_DOC
shell: bash
- name: Run test.sh
working-directory: ${{ env.WORKDIR }}
run: |
${{ env.WORKDIR }}/test.sh
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 kunitsuinc
Copyright 2022 kunitsucom

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
82 changes: 41 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# rec.sh - JSON logger for POSIX Shell Script
# log.sh - JSON logger for POSIX Shell Script

rec.sh is a lightweight and no dependencies JSON logger for POSIX Shell Script.
log.sh is a lightweight and no dependencies JSON logger for POSIX Shell Script.

This logger has been minimized as much as possible for copy-and-paste portability, at the expense of readability.

**NOTE:** rec.sh only supports JSON with string values. JSON such as `{"number":123}` cannot be output. In the case of rec.sh, it will be `{"number":"123"}`.
**NOTE:** log.sh only supports JSON with string values. JSON such as `{"number":123}` cannot be output. In the case of log.sh, it will be `{"number":"123"}`.

**NOTE:** rec.sh cannot output any control characters other than `\n` `\r` `\t`.
**NOTE:** log.sh cannot output any control characters other than `\n` `\r` `\t`.

## HOW TO USE

There are two ways.

### 1. Vendoring (Recommended)
### 1. Vendoring (recommended)

Copy the rec.sh functions in the shell script file ([`index.html`](/index.html)) and paste them where you want to use them.
(file name `index.html` may seem strange, but it's necessary for me to serve Shell Script file in GitHub Pages with as short URL *https://kunitsuinc.github.io/rec.sh/* as possible)
Copy the log.sh functions in the shell script file ([`index.html`](/index.html)) and paste them where you want to use them.
(file name `index.html` may seem strange, but it's necessary for me to serve Shell Script file in GitHub Pages with as short URL [`https://kunitsucom.github.io/log.sh/`](https://kunitsucom.github.io/log.sh/) as possible)

### 2. Use via HTTP

You can load a shell script function via the Internet as follows:

```console
$ eval "$(curl -fLSs --tlsv1.2 https://kunitsuinc.github.io/rec.sh/)"
$ eval "$(curl -fLSs --tlsv1.2 https://kunitsucom.github.io/log.sh/)"

$ RecInfoJSON hello foo bar HOSTNAME ${HOSTNAME}
$ LogshInfoJSON hello foo bar HOSTNAME ${HOSTNAME}
{"timestamp":"2021-11-26T08:02:08+09:00","severity":"INFO","caller":"-bash","message":"hello","foo":"bar","HOSTNAME":"localhost"} # <- NOTE: stderr

$ # And so on...
Expand All @@ -33,11 +33,11 @@ $ # And so on...
## Examples of usage

```console
$ # RecDefaultJSON, RecDebugJSON, RecInfoJSON, RecNoticeJSON, RecWarningJSON, RecErrorJSON, RecCriticalJSON, RecAlertJSON and RecEmergencyJSON
$ RecInfoJSON hello foo bar HOSTNAME ${HOSTNAME} ctrl "$(printf "\n\t\r")" cannot-tail-lf "$(printf "\t\r\n")" cannot-other-ctrl-chars "$(printf "\x01\x7F")"
$ # LogshDefaultJSON, LogshDebugJSON, LogshInfoJSON, LogshNoticeJSON, LogshWarningJSON, LogshErrorJSON, LogshCriticalJSON, LogshAlertJSON and LogshEmergencyJSON
$ LogshInfoJSON hello foo bar HOSTNAME ${HOSTNAME} ctrl "$(printf "\n\t\r")" cannot-tail-lf "$(printf "\t\r\n")" cannot-other-ctrl-chars "$(printf "\x01\x7F")"
{"timestamp":"2021-11-26T08:02:08+09:00","severity":"INFO","caller":"-bash","message":"hello","foo":"bar","HOSTNAME":"localhost","ctrl":"\n\t\r","cannot-tail-lf":"\t\r","cannot-other-ctrl-chars":""} # <- NOTE: stderr

$ RecInfoJSON hello foo bar HOSTNAME ${HOSTNAME} ctrl "$(printf "\n\t\r")" cannot-tail-lf "$(printf "\t\r\n")" cannot-other-ctrl-chars "$(printf "\x01\x7F")" 2>&1 | jq .
$ LogshInfoJSON hello foo bar HOSTNAME ${HOSTNAME} ctrl "$(printf "\n\t\r")" cannot-tail-lf "$(printf "\t\r\n")" cannot-other-ctrl-chars "$(printf "\x01\x7F")" 2>&1 | jq .
{
"timestamp": "2021-11-26T08:02:34+09:00",
"severity": "INFO",
Expand All @@ -46,43 +46,43 @@ $ RecInfoJSON hello foo bar HOSTNAME ${HOSTNAME} ctrl "$(printf "\n\t\r")" canno
"foo": "bar",
"HOSTNAME": "localhost",
"ctrl": "\n\t\r",
"cannot-tail-lf": "\t\r" # <- NOTE: rec.sh can't output field value tail '\n'
"cannot-other-ctrl-chars": "" # <- NOTE: rec.sh can't output other control characters
"cannot-tail-lf": "\t\r" # <- NOTE: log.sh can't output field value tail '\n'
"cannot-other-ctrl-chars": "" # <- NOTE: log.sh can't output other control characters
}
```

```console
$ # Severity threshold
$ export REC_SEVERITY=0; RecDefaultJSON "output"; RecDebugJSON "output"; RecInfoJSON "output"
$ export LOGSH_LEVEL=0; LogshDefaultJSON "output"; LogshDebugJSON "output"; LogshInfoJSON "output"
{"timestamp":"2021-11-28T10:28:24+09:00","severity":"DEFAULT","caller":"-bash","message":"output"}
{"timestamp":"2021-11-28T10:28:24+09:00","severity":"DEBUG","caller":"-bash","message":"output"}
{"timestamp":"2021-11-28T10:28:24+09:00","severity":"INFO","caller":"-bash","message":"output"}

$ export REC_SEVERITY=1; RecDefaultJSON "NO OUTPUT"; RecDebugJSON "output"; RecInfoJSON "output"
$ export LOGSH_LEVEL=1; LogshDefaultJSON "NO OUTPUT"; LogshDebugJSON "output"; LogshInfoJSON "output"
{"timestamp":"2021-11-28T10:28:24+09:00","severity":"DEBUG","caller":"-bash","message":"output"}
{"timestamp":"2021-11-28T10:28:24+09:00","severity":"INFO","caller":"-bash","message":"output"}

$ export REC_SEVERITY=101; RecDefaultJSON "NO OUTPUT"; RecDebugJSON "NO OUTPUT"; RecInfoJSON "output"
$ export LOGSH_LEVEL=101; LogshDefaultJSON "NO OUTPUT"; LogshDebugJSON "NO OUTPUT"; LogshInfoJSON "output"
{"timestamp":"2021-11-28T10:28:24+09:00","severity":"INFO","caller":"-bash","message":"output"}

$ # +------------------+------------------------+
$ # | Function | REC_SEVERITY threshold |
$ # | Function | LOGSH_LEVEL threshold |
$ # +------------------+------------------------+
$ # | RecDefaultJSON | 0 |
$ # | RecDebugJSON | 100 |
$ # | RecInfoJSON | 200 |
$ # | RecNoticeJSON | 300 |
$ # | RecWarningJSON | 400 |
$ # | RecErrorJSON | 500 |
$ # | RecCriticalJSON | 600 |
$ # | RecAlertJSON | 700 |
$ # | RecEmergencyJSON | 800 |
$ # | LogshDefaultJSON | 0 |
$ # | LogshDebugJSON | 100 |
$ # | LogshInfoJSON | 200 |
$ # | LogshNoticeJSON | 300 |
$ # | LogshWarningJSON | 400 |
$ # | LogshErrorJSON | 500 |
$ # | LogshCriticalJSON | 600 |
$ # | LogshAlertJSON | 700 |
$ # | LogshEmergencyJSON | 800 |
$ # +------------------+------------------------+
```

```console
$ # Change timestamp timezone
$ TZ=UTC RecInfoJSON hello foo bar 2>&1 | jq .
$ TZ=UTC LogshInfoJSON hello foo bar 2>&1 | jq .
{
"timestamp": "2021-11-27T11:19:15+00:00", # <- NOTE: TZ=UTC
"severity": "INFO",
Expand All @@ -94,30 +94,30 @@ $ TZ=UTC RecInfoJSON hello foo bar 2>&1 | jq .

```console
$ # Change field key name
$ export REC_TIMESTAMP_KEY=ts REC_SEVERITY_KEY=lv REC_CALLER_KEY=file REC_MESSAGE_KEY=msg
$ RecInfoJSON hello foo bar 2>&1 | jq .
$ export LOGSH_TIMESTAMP_KEY=ts LOGSH_LEVEL_KEY=lv LOGSH_CALLER_KEY=file LOGSH_MESSAGE_KEY=msg
$ LogshInfoJSON hello foo bar 2>&1 | jq .
{
"ts": "2021-11-27T20:21:55+09:00", # <- NOTE: REC_TIMESTAMP_KEY
"lv": "INFO", # <- NOTE: REC_SEVERITY_KEY
"file": "-bash", # <- NOTE: REC_CALLER_KEY
"msg": "hello", # <- NOTE: REC_MESSAGE_KEY
"ts": "2021-11-27T20:21:55+09:00", # <- NOTE: LOGSH_TIMESTAMP_KEY
"lv": "INFO", # <- NOTE: LOGSH_LEVEL_KEY
"file": "-bash", # <- NOTE: LOGSH_CALLER_KEY
"msg": "hello", # <- NOTE: LOGSH_MESSAGE_KEY
"foo": "bar"
}
```

```console
$ # RecExecJSON
$ RecExecJSON date +%F
$ # LogshExecJSON
$ LogshExecJSON date +%F
{"timestamp":"2021-11-27T20:25:03+09:00","severity":"INFO","caller":"-bash","message":"$ date +%F"} # <- NOTE: stderr
2021-11-25
```

```console
$ # RecRunJSON
$ RecRunJSON sh -c "echo out; echo err 1>&2; exit 1"
$ # LogshRunJSON
$ LogshRunJSON sh -c "echo out; echo err 1>&2; exit 1"
{"timestamp":"2021-11-27T20:25:27+09:00","severity":"INFO","caller":"-bash","message":"$ date +%F","command":"date +%F","stdout":"2021-11-27","stderr":"","return":"1"} # <- NOTE: stderr

$ RecRunJSON sh -c "echo out; echo err 1>&2; exit 1" 2>&1 | jq .
$ LogshRunJSON sh -c "echo out; echo err 1>&2; exit 1" 2>&1 | jq .
{
"timestamp": "2021-11-27T20:26:46+09:00",
"severity": "INFO",
Expand All @@ -134,5 +134,5 @@ $ RecRunJSON sh -c "echo out; echo err 1>&2; exit 1" 2>&1 | jq .

The following tools are used for development.

- formatter ... https://github.com/mvdan/sh
- linter ... https://github.com/koalaman/shellcheck
- formatter ... [`github.com/mvdan/sh`](https://github.com/mvdan/sh)
- linter ... [`github.com/koalaman/shellcheck`](https://github.com/koalaman/shellcheck)
Loading

0 comments on commit 9b84c67

Please sign in to comment.