From 352fa532395887fe9b699706b7cee73f255d98d6 Mon Sep 17 00:00:00 2001 From: ginokent <29125616+ginokent@users.noreply.github.com> Date: Sun, 5 Jan 2025 20:07:38 +0900 Subject: [PATCH 1/4] BREAKING CHANGE: transfer repository to hakadoriya organization --- .github/CODEOWNERS | 2 + .github/dependabot.yml | 22 ++ .github/pull_request_template.md | 29 ++ .github/workflows/auto-assign.yml | 23 ++ .github/workflows/label-checker.yml | 80 ++++ .github/workflows/sh-test.yml | 27 +- .github/workflows/task-list-checker.yml | 22 ++ .github/workflows/typo-checker.yml | 46 +++ LICENSE | 2 +- README.md | 10 +- bin/benchmark.sh | 107 ++++++ bin/build.sh | 24 ++ bin/test.sh | 32 ++ bin/testcases.sh | 467 ++++++++++++++++++++++++ index.html => docs/index.html | 10 +- log.sh | 54 ++- rec.sh | 1 - 17 files changed, 925 insertions(+), 33 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/auto-assign.yml create mode 100644 .github/workflows/label-checker.yml create mode 100644 .github/workflows/task-list-checker.yml create mode 100644 .github/workflows/typo-checker.yml create mode 100755 bin/benchmark.sh create mode 100755 bin/build.sh create mode 100755 bin/test.sh create mode 100755 bin/testcases.sh rename index.html => docs/index.html (96%) mode change 120000 => 100644 log.sh delete mode 120000 rec.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..1500e3a --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# ref: https://docs.github.com/ja/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-code-owners +* @hakadoriya/owner diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4a0ef41 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + day: "monday" + time: "11:00" + timezone: "Asia/Tokyo" + commit-message: + prefix: "ci(github-actions): " + labels: + - "ci" + assignees: + - "hakadoriya/owner" + reviewers: + - "hakadoriya/owner" + groups: + dependencies: + patterns: + - "*" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..20d8e75 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,29 @@ + + +## Ticket / Issue Number + +> **Note** +> *Please fill in the ticket or issue number.* +> > Example: +> > +> > #1 + +## What's changed + +> **Note** +> *Please explain what changes this pull request will make.* +> > Example: +> > +> > - Added functionality to perform 'bar' on 'foo'. + +## Check List + +- [ ] Assign labels +- [ ] Add appropriate test cases + +## Remark + +> **Note** +> *Please provide additional remarks if necessary.* + + diff --git a/.github/workflows/auto-assign.yml b/.github/workflows/auto-assign.yml new file mode 100644 index 0000000..b379f69 --- /dev/null +++ b/.github/workflows/auto-assign.yml @@ -0,0 +1,23 @@ +name: auto-assign + +on: + pull_request: + types: + - opened + - ready_for_review + - reopened + +jobs: + auto-assign: + name: Auto Assign + if: github.actor != 'dependabot[bot]' + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - if: ${{ toJSON(github.event.pull_request.assignees) == '[]' }} + run: gh pr edit "${NUMBER}" --add-assignee "${ASSIGNEE}" + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + NUMBER: ${{ github.event.pull_request.number }} + ASSIGNEE: ${{ github.event.pull_request.user.login }} diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml new file mode 100644 index 0000000..a609a2b --- /dev/null +++ b/.github/workflows/label-checker.yml @@ -0,0 +1,80 @@ +name: label-checker + +# Dependabot +# gh label create --force "dependencies" --description "Pull requests that update a dependency file" --color 0366D6 +# gh label create --force "go" --description "Pull requests that update Go code" --color 16E2E2 +# gh label create --force "github_actions" --description "Pull requests that update GitHub Actions code" --color 000000 +# gh label create --force "docker" --description "Pull requests that update Docker code" --color 21CEFF + +# Renovate +# gh label create --force "renovate" --description "Renovate" --color 009485 + +# Commit prefix +# gh label create --force "BREAKING CHANGE" --description "BREAKING CHANGES" --color FF0303 +# gh label create --force "build" --description "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)" --color 5319E7 +# gh label create --force "ci" --description "Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)" --color 53C4EE +# gh label create --force "docs" --description "Documentation only changes" --color 1B3E44 +# gh label create --force "feat" --description "A new feature" --color 0EAA80 +# gh label create --force "fix" --description "A bug fix" --color 1D76DB +# gh label create --force "perf" --description "A code change that improves performance" --color A2EEEF +# gh label create --force "refactor" --description "A code change that neither fixes a bug nor adds a feature" --color C5DEF5 +# gh label create --force "test" --description "Adding missing tests or correcting existing tests" --color 1D76DB +# gh label create --force "chore" --description "Changes to the build process or auxiliary tools and libraries such as documentation generation" --color 20313F + +on: + pull_request: + types: + - opened + - edited + - labeled + - unlabeled + - ready_for_review + - reopened + - synchronize + +env: + LABELS: "BREAKING CHANGE,build,ci,docs,feat,fix,perf,refactor,test,chore" + +jobs: + label-checker: + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + id-token: write + contents: read + pull-requests: write # required to add labels + statuses: read + checks: read + repository-projects: read + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} # needed for gh pr view + - name: Check labels + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + # Check labels + set -Eeuo pipefail -x + + # If any of the labels are present, exit with success + if [[ -n "$(gh pr view --json labels --jq ".labels[].name" | grep -E "^($(tr , "|" <<<"${LABELS:?}"))$")" ]]; then + exit 0 + fi + + # Add labels based on PR title + GH_PR_TITLE=$(gh pr view --json title --jq .title) + gh label list --json name --jq ".[].name" | while read -r LINE; do + awk -F: "/^${LINE-}(\([^\)]+\))?:/ {print \$1}" <<<"${GH_PR_TITLE:?}" | grep -Eo "^${LINE:?}" || true # NOTE: Ignore the return value of grep because we just want to output the string + done | xargs -t -I{} gh pr edit --add-label {} + + # If any of the labels are present, exit with success + while read -r LINE; do + if grep -E "^($(tr , "|" <<<"${LABELS:?}"))$" <<<"${LINE-}"; then + exit 0 + fi + done <<<"$(gh pr view --json labels --jq ".labels[].name")" + + # If none of the labels are present, exit with error + exit 1 diff --git a/.github/workflows/sh-test.yml b/.github/workflows/sh-test.yml index 73a4227..e12c667 100644 --- a/.github/workflows/sh-test.yml +++ b/.github/workflows/sh-test.yml @@ -1,27 +1,16 @@ name: sh-test -# ~~~~~~~ -# https://github.com/kunitsucom/log.sh/workflows/sh-test/badge.svg -# ~~~~~~~ +# ^^^^^^^ +# https://github.com/organization/repository/workflows/sh-test/badge.svg +# ^^^^^^^ on: push: - branches: - - main - paths-ignore: - - '.github/dependabot.yml' - - '.github/pull_request_template.md' - - '.github/release.yml' - - 'README.md' + # NO paths-ignore pull_request: - paths-ignore: - - '.github/dependabot.yml' - - '.github/pull_request_template.md' - - '.github/release.yml' - - 'README.md' + # NO paths-ignore workflow_dispatch: - inputs: {} -# NOTE: 連続で commit & push した時に最新の commit 以外のワークフローをキャンセルする +# NOTE: Cancel the previous run of the same workflow if it's still running concurrency: group: ${{ github.workflow }}-${{ github.base_ref }}-${{ github.head_ref }}-${{ github.ref }} cancel-in-progress: true @@ -41,7 +30,7 @@ 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 + - uses: actions/checkout@v4 - name: DEBUG run: | cat <<'DEBUG_DOC' @@ -58,4 +47,4 @@ jobs: - name: Run test.sh working-directory: ${{ env.WORKDIR }} run: | - ${{ env.WORKDIR }}/test.sh + ${{ env.WORKDIR }}/bin/test.sh diff --git a/.github/workflows/task-list-checker.yml b/.github/workflows/task-list-checker.yml new file mode 100644 index 0000000..7cc1331 --- /dev/null +++ b/.github/workflows/task-list-checker.yml @@ -0,0 +1,22 @@ +name: task-list-checker + +on: + pull_request: + types: + - opened + - edited + - ready_for_review + - reopened + - synchronize + +jobs: + task-list-checker: + if: github.actor != 'dependabot[bot]' + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + pull-requests: read + steps: + - uses: hakadoriya/github-actions-task-list-checker@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/typo-checker.yml b/.github/workflows/typo-checker.yml new file mode 100644 index 0000000..606bb3e --- /dev/null +++ b/.github/workflows/typo-checker.yml @@ -0,0 +1,46 @@ +name: typo-checker +# ^^^^^^^^^^^^ +# https://github.com/organization/repository/workflows/typo-checker/badge.svg +# ^^^^^^^^^^^^ + +on: + pull_request: + workflow_dispatch: + inputs: {} + +# NOTE: If commit & push continuously, cancel the workflow other than the latest 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: + typo-checker: # 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@v4 + - name: DEBUG + shell: bash + 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 + - name: Check spelling + uses: crate-ci/typos@master diff --git a/LICENSE b/LICENSE index a49f4fa..554f5ff 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2022 kunitsucom + Copyright 2022 hakadoriya Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 77e8872..bf8886d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -# 🚧 Moved [https://github.com/hakadoriya/log.sh](https://github.com/hakadoriya/log.sh) 🚧 - # log.sh - JSON logger for POSIX Shell Script -[![license](https://img.shields.io/github/license/kunitsucom/log.sh)](LICENSE) -[![workflow](https://github.com/kunitsucom/log.sh/workflows/sh-test/badge.svg)](https://github.com/kunitsucom/log.sh/tree/main) +[![license](https://img.shields.io/github/license/hakadoriya/log.sh)](LICENSE) +[![workflow](https://github.com/hakadoriya/log.sh/workflows/sh-test/badge.svg)](https://github.com/hakadoriya/log.sh/tree/main) log.sh is a lightweight and no dependencies JSON logger for POSIX Shell Script. @@ -20,14 +18,14 @@ There are two ways. ### 1. Vendoring (recommended) 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) +(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://hakadoriya.github.io/log.sh/`](https://hakadoriya.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://kunitsucom.github.io/log.sh/)" +$ eval "$(curl -fLSs --tlsv1.2 https://hakadoriya.github.io/log.sh/)" $ 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 diff --git a/bin/benchmark.sh b/bin/benchmark.sh new file mode 100755 index 0000000..f971399 --- /dev/null +++ b/bin/benchmark.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +set -E -e -o pipefail -u + +# benchmark sample on commit 'init' +# ------------------------------------------------------------------------------------------------- +# $ docker run -it --rm -v "$(pwd -P)":"$(pwd -P)" -w "$(pwd -P)" --env-file <(env) ubuntu:20.04 ./benchmark.sh +# {"timestamp":"2021-11-28T02:40:48+00:00","severity":"INFO","caller":"./benchmark.sh","message":"$ sh -c 'uname -s -v -m; grep model.name /proc/cpuinfo | sort -u'"} +# Linux #1 SMP Sat Jul 3 21:51:47 UTC 2021 x86_64 +# model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz +# +# BenchmarkLogshDebug_001 +# LogshDebug(message only) * 100 +# real 0m0.596s +# user 0m0.397s +# sys 0m0.556s +# +# BenchmarkLogshDebug_002 +# LogshDebug(with 1 field) * 100 +# real 0m0.878s +# user 0m0.608s +# sys 0m0.876s +# ------------------------------------------------------------------------------------------------- +# $ ./benchmark.sh +# {"timestamp":"2021-11-28T02:39:38+00:00","severity":"INFO","caller":"./benchmark.sh","message":"$ sh -c 'uname -s -v -m; sysctl -a machdep.cpu.brand_string'"} +# Darwin Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64 +# machdep.cpu.brand_string: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz +# +# BenchmarkLogshDebug_001 +# LogshDebug(message only) * 100 +# real 0m3.694s +# user 0m0.702s +# sys 0m2.035s +# +# BenchmarkLogshDebug_002 +# LogshDebug(with 1 field) * 100 +# real 0m5.973s +# user 0m1.154s +# sys 0m3.422s +# ------------------------------------------------------------------------------------------------- +# $ ./benchmark.sh +# 2022-04-09T07:30:54+00:00 [ INFO] $ sh -c 'uname -s -v -m; sysctl -a machdep.cpu.brand_string' +# Darwin Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64 +# machdep.cpu.brand_string: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz +# +# BenchmarkLogshDebugJSON_001 +# LogshDebugJSON(message only) * 100 +# real 0m1.890s +# user 0m0.730s +# sys 0m1.639s +# +# BenchmarkLogshDebugJSON_002 +# LogshDebugJSON(with 1 field) * 100 +# real 0m3.108s +# user 0m1.219s +# sys 0m2.855s +# ------------------------------------------------------------------------------------------------- +# $ ./benchmark.sh +# 2023-08-26T19:23:55+00:00 [ INFO] $ sh -c 'uname -s -v -m; sysctl -a machdep.cpu.brand_string' +# Darwin Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64 +# machdep.cpu.brand_string: Apple M1 Max +# +# BenchmarkLogshDebugJSON_001 +# LogshDebugJSON(message only) * 100 +# real 0m1.132s +# user 0m0.198s +# sys 0m0.748s +# +# BenchmarkLogshDebugJSON_002 +# LogshDebugJSON(with 1 field) * 100 +# real 0m1.800s +# user 0m0.320s +# sys 0m1.225s +# ------------------------------------------------------------------------------------------------- + +cd "$(dirname "$0")" + +# shellcheck disable=SC1091 +. ./log.sh + +export TZ=UTC LOGSH_LEVEL=0 LOGSH_TIMESTAMP_KEY=timestamp LOGSH_LEVEL_KEY=severity LOGSH_CALLER_KEY=caller LOGSH_MESSAGE_KEY=message + +DisplayRuntimeInfo() { + LogshRun uname -s -v -m + __system=$(uname -s) + if [ "${__system:-}" = Linux ]; then + LogshRun sh -c "grep model.name /proc/cpuinfo | sort -u" + elif [ "${__system:-}" = Darwin ]; then + LogshRun sysctl -a machdep.cpu.brand_string + else + LogshWarning unknown system + fi + echo +} && DisplayRuntimeInfo + +BenchmarkLogshDebugJSON_001() { + echo "BenchmarkLogshDebugJSON_001" + printf %s 'LogshDebugJSON(message only) * 100' + time : "$(for _ in $(seq 1 100); do LogshDebugJSON "$(printf "\t\nA\t\nB\t\nC\t\n")"; done >/tmp/log.sh_BenchmarkLogshDebugJSON_001.log 2>&1)" + echo +} && BenchmarkLogshDebugJSON_001 + +BenchmarkLogshDebugJSON_002() { + echo "BenchmarkLogshDebugJSON_002" + printf %s 'LogshDebugJSON(with 1 field) * 100' + time : "$(for _ in $(seq 1 100); do LogshDebugJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")"; done >/tmp/log.sh_BenchmarkLogshDebugJSON_002.log 2>&1)" + echo +} && BenchmarkLogshDebugJSON_002 diff --git a/bin/build.sh b/bin/build.sh new file mode 100755 index 0000000..cbbadb4 --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# LICENSE: https://github.com/hakadoriya/log.sh/blob/HEAD/LICENSE +# Common +if [ "${LOGSH_COLOR:-}" ] || [ -t 2 ] ; then LOGSH_COLOR=true; else LOGSH_COLOR=''; fi +_logshRFC3339() { date "+%Y-%m-%dT%H:%M:%S%z" | sed "s/\(..\)$/:\1/"; } +_logshCmd() { for a in "$@"; do if echo "${a:-}" | grep -Eq "[[:blank:]]"; then printf "'%s' " "${a:-}"; else printf "%s " "${a:-}"; fi; done | sed "s/ $//"; } +# Color +LogshInfo() { test " ${LOGSH_LEVEL:-0}" -gt 200 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;32m} INFO${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; } +LogshError() { test " ${LOGSH_LEVEL:-0}" -gt 500 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;31m} ERROR${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; } +LogshExec() { LogshInfo "$ $(_logshCmd "$@")" && "$@"; } + +main () { + # cd to the parent directory of this script + if ! LogshExec cd "$(dirname "$0")/.."; then + LogshError "cd failed" + exit 1 + fi + # copy log.sh to docs + LogshExec cp -a ./log.sh ./docs/index.html + # done + LogshInfo "done" +} && main "$@" diff --git a/bin/test.sh b/bin/test.sh new file mode 100755 index 0000000..3b93018 --- /dev/null +++ b/bin/test.sh @@ -0,0 +1,32 @@ +#!/bin/sh +set -e -u + +cd "$(dirname "$0")/.." + +# shellcheck disable=SC1091 +. ./log.sh + +export TZ=UTC LOGSH_COLOR=true LOGSH_LEVEL=0 LOGSH_TIMESTAMP_KEY=timestamp LOGSH_LEVEL_KEY=severity LOGSH_CALLER_KEY=caller LOGSH_MESSAGE_KEY=message + +err=0 + +# begin log +LogshInfo "RUN: $0" +# end log +trap 'if [ ${err:-0} -gt 0 ]; then + LogshError "FAIL: $0" + exit ${err:-1} +else + LogshInfo "PASS: $0" + exit 0 +fi +' EXIT + +# local +./bin/testcases.sh || err=$((err+$?)) +# debian:12 +docker run --rm -v "$(pwd -P)":"$(pwd -P)" -w "$(pwd -P)" -e LOGSH_COLOR=true debian:12 ./bin/testcases.sh || err=$((err+$?)) +# ubuntu:22.04 dash +docker run --rm -v "$(pwd -P)":"$(pwd -P)" -w "$(pwd -P)" -e LOGSH_COLOR=true ubuntu:22.04 dash ./bin/testcases.sh || err=$((err+$?)) +# ubuntu:22.04 bash +docker run --rm -v "$(pwd -P)":"$(pwd -P)" -w "$(pwd -P)" -e LOGSH_COLOR=true ubuntu:22.04 bash ./bin/testcases.sh || err=$((err+$?)) diff --git a/bin/testcases.sh b/bin/testcases.sh new file mode 100755 index 0000000..1d73f98 --- /dev/null +++ b/bin/testcases.sh @@ -0,0 +1,467 @@ +#!/bin/sh +set -e -u + +cd "$(dirname "$0")/.." + +# shellcheck disable=SC1091 +. ./log.sh + +export TZ=UTC LOGSH_COLOR=true LOGSH_LEVEL=0 LOGSH_TIMESTAMP_KEY=timestamp LOGSH_LEVEL_KEY=severity LOGSH_CALLER_KEY=caller LOGSH_MESSAGE_KEY=message + +err=0 + +# begin log +LogshRun uname -a +LogshInfo "RUN: $0" +# end log +trap 'if [ ${err:-0} -gt 0 ]; then + LogshError "FAIL: $0" + exit ${err:-1} +else + LogshInfo "PASS: $0" + exit 0 +fi +' EXIT + +# +# LogshDefault +# + +TestLogshDefault_001() { + LogshInfo " RUN: TestLogshDefault_001" + export LOGSH_LEVEL=0 + expect='^[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00 \[.*DEFAULT.*\] LOG$' + actual=$(LogshDefault "LOG" 2>&1) + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshDefault_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshDefault_001" +} && TestLogshDefault_001 || err=$((err+$?)) + +TestLogshDefault_002() { + LogshInfo " RUN: TestLogshDefault_002" + export LOGSH_LEVEL=1 + actual=$(LogshDefault "LOG" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshDefault_002" + return 1 + fi + LogshInfo " PASS: TestLogshDefault_002" +} && TestLogshDefault_002 || err=$((err+$?)) + +# +# LogshDefaultJSON +# + +TestLogshDefaultJSON_001() { + LogshInfo " RUN: TestLogshDefaultJSON_001" + export LOGSH_LEVEL=0 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"DEFAULT","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshDefaultJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshDefaultJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshDefaultJSON_001" +} && TestLogshDefaultJSON_001 || err=$((err+$?)) + +TestLogshDefaultJSON_002() { + LogshInfo " RUN: TestLogshDefaultJSON_002" + export LOGSH_LEVEL=1 + actual=$(LogshDefaultJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshDefaultJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshDefaultJSON_002" +} && TestLogshDefaultJSON_002 || err=$((err+$?)) + +# +# LogshDebugJSON +# + +TestLogshDebugJSON_001() { + LogshInfo " RUN: TestLogshDebugJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=100 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"DEBUG","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshDebugJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshDebugJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshDebugJSON_001" +} && TestLogshDebugJSON_001 || err=$((err+$?)) + +TestLogshDebugJSON_002() { + LogshInfo " RUN: TestLogshDebugJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=101 + actual=$(LogshDebugJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshDebugJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshDebugJSON_002" +} && TestLogshDebugJSON_002 || err=$((err+$?)) + +# +# LogshInfoJSON +# + +TestLogshInfoJSON_001() { + LogshInfo " RUN: TestLogshInfoJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=200 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"INFO","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshInfoJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshInfoJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshInfoJSON_001" +} && TestLogshInfoJSON_001 || err=$((err+$?)) + +TestLogshInfoJSON_002() { + LogshInfo " RUN: TestLogshInfoJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=201 + actual=$(LogshInfoJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshInfoJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshInfoJSON_002" +} && TestLogshInfoJSON_002 || err=$((err+$?)) + +# +# LogshNoticeJSON +# + +TestLogshNoticeJSON_001() { + LogshInfo " RUN: TestLogshNoticeJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=300 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"NOTICE","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshNoticeJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshNoticeJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshNoticeJSON_001" +} && TestLogshNoticeJSON_001 || err=$((err+$?)) + +TestLogshNoticeJSON_002() { + LogshInfo " RUN: TestLogshNoticeJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=301 + actual=$(LogshNoticeJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshNoticeJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshNoticeJSON_002" +} && TestLogshNoticeJSON_002 || err=$((err+$?)) + +# +# LogshWarningJSON +# + +TestLogshWarningJSON_001() { + LogshInfo " RUN: TestLogshWarningJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=400 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"WARNING","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshWarningJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshWarningJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshWarningJSON_001" +} && TestLogshWarningJSON_001 || err=$((err+$?)) + +TestLogshWarningJSON_002() { + LogshInfo " RUN: TestLogshWarningJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=401 + actual=$(LogshWarningJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshWarningJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshWarningJSON_002" +} && TestLogshWarningJSON_002 || err=$((err+$?)) + +# +# LogshErrorJSON +# + +TestLogshErrorJSON_001() { + LogshInfo " RUN: TestLogshErrorJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=500 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"ERROR","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshErrorJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshErrorJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshErrorJSON_001" +} && TestLogshErrorJSON_001 || err=$((err+$?)) + +TestLogshErrorJSON_002() { + LogshInfo " RUN: TestLogshErrorJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=501 + actual=$(LogshErrorJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshErrorJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshErrorJSON_002" +} && TestLogshErrorJSON_002 || err=$((err+$?)) + +# +# LogshCriticalJSON +# + +TestLogshCriticalJSON_001() { + LogshInfo " RUN: TestLogshCriticalJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=600 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"CRITICAL","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshCriticalJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshCriticalJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshCriticalJSON_001" +} && TestLogshCriticalJSON_001 || err=$((err+$?)) + +TestLogshCriticalJSON_002() { + LogshInfo " RUN: TestLogshCriticalJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=601 + actual=$(LogshCriticalJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshCriticalJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshCriticalJSON_002" +} && TestLogshCriticalJSON_002 || err=$((err+$?)) + +# +# LogshAlertJSON +# + +TestLogshAlertJSON_001() { + LogshInfo " RUN: TestLogshAlertJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=700 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"ALERT","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshAlertJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshAlertJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshAlertJSON_001" +} && TestLogshAlertJSON_001 || err=$((err+$?)) + +TestLogshAlertJSON_002() { + LogshInfo " RUN: TestLogshAlertJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=701 + actual=$(LogshAlertJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshAlertJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshAlertJSON_002" +} && TestLogshAlertJSON_002 || err=$((err+$?)) + +# +# LogshEmergencyJSON +# + +TestLogshEmergencyJSON_001() { + LogshInfo " RUN: TestLogshEmergencyJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=800 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"EMERGENCY","caller":".+/testcases.sh","message":"\\t\\nA\\t\\nB\\t\\nC\\t","test":"\\t\\nA\\t\\nB\\t\\nC\\t"}$' + actual=$(LogshEmergencyJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshEmergencyJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshEmergencyJSON_001" +} && TestLogshEmergencyJSON_001 || err=$((err+$?)) + +TestLogshEmergencyJSON_002() { + LogshInfo " RUN: TestLogshEmergencyJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=801 + actual=$(LogshEmergencyJSON "$(printf "\t\nA\t\nB\t\nC\t\n")" "test" "$(printf "\t\nA\t\nB\t\nC\t\n")" 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshEmergencyJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshEmergencyJSON_002" +} && TestLogshEmergencyJSON_002 || err=$((err+$?)) + +# +# LogshExecJSON +# + +TestLogshExecJSON_001() { + LogshInfo " RUN: TestLogshExecJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=100 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"INFO","caller":".+/testcases.sh","message":". true"}$' + actual=$(LogshExecJSON true 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshExecJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshExecJSON_001" +} && TestLogshExecJSON_001 || err=$((err+$?)) + +TestLogshExecJSON_002() { + LogshInfo " RUN: TestLogshExecJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=201 + actual=$(LogshExecJSON true 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshExecJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshExecJSON_002" +} && TestLogshExecJSON_002 || err=$((err+$?)) + +# +# LogshRunJSON +# + +TestLogshRunJSON_001() { + LogshInfo " RUN: TestLogshRunJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=100 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"INFO","caller":".+/testcases.sh","message":". date .%Y-%m-%d","command":"date .%Y-%m-%d","stdout":"[0-9]+-[0-9]+-[0-9]+","stderr":"","return":"0"}$' + actual=$(LogshRunJSON date +%Y-%m-%d 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestLogshRunJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestLogshRunJSON_001" +} && TestLogshRunJSON_001 || err=$((err+$?)) + +TestLogshRunJSON_002() { + LogshInfo " RUN: TestLogshRunJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=201 + actual=$(LogshRunJSON date +%Y-%m-%d 2>&1) + unset LOGSH_LEVEL + if [ "${actual:-}" ]; then + LogshError " FAIL: TestLogshRunJSON_002" + return 1 + fi + LogshInfo " PASS: TestLogshRunJSON_002" +} && TestLogshRunJSON_002 || err=$((err+$?)) + +# +# common +# + +TestCommonLogshJSON_001() { + LogshInfo " RUN: TestCommonLogshJSON_001" + unset LOGSH_LEVEL + export LOGSH_LEVEL=0 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"DEFAULT","caller":".+/testcases.sh","message":""}$' + actual=$(LogshDefaultJSON 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestCommonLogshJSON_001" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestCommonLogshJSON_001" +} && TestCommonLogshJSON_001 || err=$((err+$?)) + +TestCommonLogshJSON_002() { + LogshInfo " RUN: TestCommonLogshJSON_002" + unset LOGSH_LEVEL + export LOGSH_LEVEL=0 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"DEFAULT","caller":".+/testcases.sh","message":"","testKey":""}$' + actual=$(LogshDefaultJSON "" testKey 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestCommonLogshJSON_002" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestCommonLogshJSON_002" +} && TestCommonLogshJSON_002 || err=$((err+$?)) + +TestCommonLogshJSON_003() { + LogshInfo " RUN: TestCommonLogshJSON_003" + unset LOGSH_LEVEL + export LOGSH_LEVEL=0 + expect='^{"timestamp":"[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.00:00","severity":"DEFAULT","caller":".+/testcases.sh","message":"","testKey":"testValue"}$' + actual=$(LogshDefaultJSON "" testKey testValue 2>&1) + unset LOGSH_LEVEL + if ! printf "%s" "${actual-}" | grep -Eq "$(printf "%s" "${expect}")" ; then + LogshError " FAIL: TestCommonLogshJSON_003" + printf " expect: %s\n" "${expect}" + printf " actual: %s\n" "${actual-}" + return 1 + fi + LogshInfo " PASS: TestCommonLogshJSON_003" +} && TestCommonLogshJSON_003 diff --git a/index.html b/docs/index.html similarity index 96% rename from index.html rename to docs/index.html index a65093c..34043aa 100644 --- a/index.html +++ b/docs/index.html @@ -1,10 +1,10 @@ #!/bin/sh # shellcheck disable=SC2317 -cat >/dev/null <<'#https://kunitsucom.github.io/log.sh/' +cat >/dev/null <<'#https://hakadoriya.github.io/log.sh/'
-#https://kunitsucom.github.io/log.sh/
+#https://hakadoriya.github.io/log.sh/
-# LISENCE: https://github.com/kunitsucom/log.sh/blob/HEAD/LICENSE
+# LICENSE: https://github.com/hakadoriya/log.sh/blob/HEAD/LICENSE
# Common
if [ "${LOGSH_COLOR:-}" ] || [ -t 2 ] ; then LOGSH_COLOR=true; else LOGSH_COLOR=''; fi
_logshRFC3339() { date "+%Y-%m-%dT%H:%M:%S%z" | sed "s/\(..\)$/:\1/"; }
@@ -26,7 +26,7 @@
# shellcheck disable=SC3045
echo "${SHELL-}" | grep -q "/?bash" && export -f _logshRFC3339 _logshCmd LogshDefault LogshDebug LogshInfo LogshWarning LogshError LogshCritical LogshAlert LogshEmergency LogshExec LogshRun || true
-# LISENCE: https://github.com/kunitsucom/log.sh/blob/HEAD/LICENSE
+# LICENSE: https://github.com/hakadoriya/log.sh/blob/HEAD/LICENSE
# Common
_logshRFC3339() { date "+%Y-%m-%dT%H:%M:%S%z" | sed "s/\(..\)$/:\1/"; }
_logshCmd() { for a in "$@"; do if echo "${a:-}" | grep -Eq "[[:blank:]]"; then printf "'%s' " "${a:-}"; else printf "%s " "${a:-}"; fi; done | sed "s/ $//"; }
@@ -50,4 +50,4 @@
# shellcheck disable=SC3045
echo "${SHELL-}" | grep -q "/?bash" && export -f _logshRFC3339 _logshCmd _logshEscape _logshJSON LogshDefaultJSON LogshDebugJSON LogshInfoJSON LogshNoticeJSON LogshWarningJSON LogshErrorJSON LogshCriticalJSON LogshAlertJSON LogshEmergencyJSON LogshExecJSON LogshRunJSON || true
-# (C) 2022 kunitsucom
+# (C) 2022 hakadoriya
diff --git a/log.sh b/log.sh
deleted file mode 120000
index 64233a9..0000000
--- a/log.sh
+++ /dev/null
@@ -1 +0,0 @@
-index.html
\ No newline at end of file
diff --git a/log.sh b/log.sh
new file mode 100644
index 0000000..34043aa
--- /dev/null
+++ b/log.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# shellcheck disable=SC2317
+cat >/dev/null <<'#https://hakadoriya.github.io/log.sh/'
+
+#https://hakadoriya.github.io/log.sh/
+
+# LICENSE: https://github.com/hakadoriya/log.sh/blob/HEAD/LICENSE
+# Common
+if [ "${LOGSH_COLOR:-}" ] || [ -t 2 ] ; then LOGSH_COLOR=true; else LOGSH_COLOR=''; fi
+_logshRFC3339() { date "+%Y-%m-%dT%H:%M:%S%z" | sed "s/\(..\)$/:\1/"; }
+_logshCmd() { for a in "$@"; do if echo "${a:-}" | grep -Eq "[[:blank:]]"; then printf "'%s' " "${a:-}"; else printf "%s " "${a:-}"; fi; done | sed "s/ $//"; }
+# Color
+LogshDefault() { test " ${LOGSH_LEVEL:-0}" -gt 000 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;35m} DEFAULT${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshDebug() { test " ${LOGSH_LEVEL:-0}" -gt 100 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;34m} DEBUG${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshInfo() { test " ${LOGSH_LEVEL:-0}" -gt 200 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;32m} INFO${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshNotice() { test " ${LOGSH_LEVEL:-0}" -gt 300 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;36m} NOTICE${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshWarn() { test " ${LOGSH_LEVEL:-0}" -gt 400 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;33m} WARN${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshWarning() { test " ${LOGSH_LEVEL:-0}" -gt 400 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;33m} WARNING${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshError() { test " ${LOGSH_LEVEL:-0}" -gt 500 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;31m} ERROR${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshCritical() { test " ${LOGSH_LEVEL:-0}" -gt 600 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;1;31m} CRITICAL${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshAlert() { test " ${LOGSH_LEVEL:-0}" -gt 700 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;41m} ALERT${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshEmergency() { test "${LOGSH_LEVEL:-0}" -gt 800 || echo "$*" | awk "{print \"$(_logshRFC3339) [${LOGSH_COLOR:+\\033[0;1;41m}EMERGENCY${LOGSH_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
+LogshExec() { LogshInfo "$ $(_logshCmd "$@")" && "$@"; }
+LogshRun() { _dlm="####R#E#C#D#E#L#I#M#I#T#E#R####" && _all=$({ _out=$("$@") && _rtn=$? || _rtn=$? && printf "\n%s" "${_dlm:?}${_out:-}" && return "${_rtn:-0}"; } 2>&1) && _rtn=$? || _rtn=$? && _dlmno=$(echo "${_all:-}" | sed -n "/${_dlm:?}/=") && _cmd=$(_logshCmd "$@") && _stdout=$(echo "${_all:-}" | tail -n +"${_dlmno:-1}" | sed "s/^${_dlm:?}//") && _stderr=$(echo "${_all:-}" | head -n "${_dlmno:-1}" | grep -v "^${_dlm:?}") && LogshInfo "$ ${_cmd:-}" && LogshInfo "${_stdout:-}" && { [ -z "${_stderr:-}" ] || LogshWarning "${_stderr:?}"; } && return "${_rtn:-0}"; }
+# export functions for bash
+# shellcheck disable=SC3045
+echo "${SHELL-}" | grep -q "/?bash" && export -f _logshRFC3339 _logshCmd LogshDefault LogshDebug LogshInfo LogshWarning LogshError LogshCritical LogshAlert LogshEmergency LogshExec LogshRun || true
+
+# LICENSE: https://github.com/hakadoriya/log.sh/blob/HEAD/LICENSE
+# Common
+_logshRFC3339() { date "+%Y-%m-%dT%H:%M:%S%z" | sed "s/\(..\)$/:\1/"; }
+_logshCmd() { for a in "$@"; do if echo "${a:-}" | grep -Eq "[[:blank:]]"; then printf "'%s' " "${a:-}"; else printf "%s " "${a:-}"; fi; done | sed "s/ $//"; }
+# JSON
+_logshEscape() { printf %s "${1:-}" | sed "s/\"/\\\"/g; s/\r/\\\r/g; s/\t/\\\t/g; s/$/\\\n/g" | tr -d "[:cntrl:]" | sed "s/\\\n$/\n/"; }
+# NOTE: shift 2 -> ${1+shift} && ${1+shift} ... avoid "shift: can't shift that many" error
+_logshJSON() { _svr="${1:?}" && _msg="$(_logshEscape "${2:-}")" && unset _fld _val && ${1+shift} && ${1+shift} && for a in "$@"; do if [ "${_val:-}" ]; then _fld="${_fld:?}:\"$(_logshEscape "${a:-}")\"" && unset _val && continue; fi && _fld="${_fld:-}${_fld:+,}\"${a:?"json key is not set"}\"" && _val=1; done && test $(($# % 2)) = 1 && _fld="${_fld:?}:\"\"" || true && printf "{%s}\n" "\"${LOGSH_TIMESTAMP_KEY:-timestamp}\":\"$(_logshRFC3339)\",\"${LOGSH_LEVEL_KEY:-severity}\":\"${_svr:?}\",\"${LOGSH_CALLER_KEY:-caller}\":\"$0\",\"${LOGSH_MESSAGE_KEY:-message}\":\"${_msg:-}\"${_fld:+,}${_fld:-}"; }
+LogshDefaultJSON() { test " ${LOGSH_LEVEL:-0}" -gt 000 2>/dev/null || _logshJSON DEFAULT "$@" 1>&2; }
+LogshDebugJSON() { test " ${LOGSH_LEVEL:-0}" -gt 100 2>/dev/null || _logshJSON DEBUG "$@" 1>&2; }
+LogshInfoJSON() { test " ${LOGSH_LEVEL:-0}" -gt 200 2>/dev/null || _logshJSON INFO "$@" 1>&2; }
+LogshNoticeJSON() { test " ${LOGSH_LEVEL:-0}" -gt 300 2>/dev/null || _logshJSON NOTICE "$@" 1>&2; }
+LogshWarnJSON() { test " ${LOGSH_LEVEL:-0}" -gt 400 2>/dev/null || _logshJSON WARN "$@" 1>&2; }
+LogshWarningJSON() { test " ${LOGSH_LEVEL:-0}" -gt 400 2>/dev/null || _logshJSON WARNING "$@" 1>&2; }
+LogshErrorJSON() { test " ${LOGSH_LEVEL:-0}" -gt 500 2>/dev/null || _logshJSON ERROR "$@" 1>&2; }
+LogshCriticalJSON() { test " ${LOGSH_LEVEL:-0}" -gt 600 2>/dev/null || _logshJSON CRITICAL "$@" 1>&2; }
+LogshAlertJSON() { test " ${LOGSH_LEVEL:-0}" -gt 700 2>/dev/null || _logshJSON ALERT "$@" 1>&2; }
+LogshEmergencyJSON() { test "${LOGSH_LEVEL:-0}" -gt 800 2>/dev/null || _logshJSON EMERGENCY "$@" 1>&2; }
+LogshExecJSON() { LogshInfoJSON "$ $(_logshCmd "$@")" && "$@"; }
+LogshRunJSON() { _dlm='####R#E#C#D#E#L#I#M#I#T#E#R####' && _all=$({ _out=$("$@") && _rtn=$? || _rtn=$? && printf "\n%s" "${_dlm:?}${_out:-}" && return "${_rtn:-0}"; } 2>&1) && _rtn=$? || _rtn=$? && _dlmno=$(echo "${_all:-}" | sed -n "/${_dlm:?}/=") && _cmd=$(_logshCmd "$@") && _stdout=$(echo "${_all:-}" | tail -n +"${_dlmno:-1}" | sed "s/^${_dlm:?}//") && _stderr=$(echo "${_all:-}" | head -n "${_dlmno:-1}" | grep -v "^${_dlm:?}") && LogshInfoJSON "$ ${_cmd:-}" command "${_cmd:-}" stdout "${_stdout:-}" stderr "${_stderr:-}" return "${_rtn:-0}" && return "${_rtn:-0}"; }
+# export functions for bash
+# shellcheck disable=SC3045
+echo "${SHELL-}" | grep -q "/?bash" && export -f _logshRFC3339 _logshCmd _logshEscape _logshJSON LogshDefaultJSON LogshDebugJSON LogshInfoJSON LogshNoticeJSON LogshWarningJSON LogshErrorJSON LogshCriticalJSON LogshAlertJSON LogshEmergencyJSON LogshExecJSON LogshRunJSON || true
+
+# (C) 2022 hakadoriya
diff --git a/rec.sh b/rec.sh
deleted file mode 120000
index b0590a5..0000000
--- a/rec.sh
+++ /dev/null
@@ -1 +0,0 @@
-log.sh
\ No newline at end of file
From 96dba5019536c3c1fd699493870b67a47caff524 Mon Sep 17 00:00:00 2001
From: ginokent <29125616+ginokent@users.noreply.github.com>
Date: Sun, 5 Jan 2025 20:13:23 +0900
Subject: [PATCH 2/4] chore(log.sh): Add JetBrains Mono font-family in
index.html
---
docs/index.html | 2 +-
log.sh | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/index.html b/docs/index.html
index 34043aa..1a4bc0a 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1,7 +1,7 @@
#!/bin/sh
# shellcheck disable=SC2317
cat >/dev/null <<'#https://hakadoriya.github.io/log.sh/'
-
+
#https://hakadoriya.github.io/log.sh/
# LICENSE: https://github.com/hakadoriya/log.sh/blob/HEAD/LICENSE
diff --git a/log.sh b/log.sh
index 34043aa..1a4bc0a 100644
--- a/log.sh
+++ b/log.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# shellcheck disable=SC2317
cat >/dev/null <<'#https://hakadoriya.github.io/log.sh/'
-
+
#https://hakadoriya.github.io/log.sh/
# LICENSE: https://github.com/hakadoriya/log.sh/blob/HEAD/LICENSE
From e599a3047c61902210e39045ee4c51a1765bc72d Mon Sep 17 00:00:00 2001
From: ginokent <29125616+ginokent@users.noreply.github.com>
Date: Sun, 5 Jan 2025 20:14:39 +0900
Subject: [PATCH 3/4] docs: Update .github/pull_request_template.md
---
.github/pull_request_template.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 20d8e75..a57dbe8 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -19,6 +19,8 @@
## Check List
- [ ] Assign labels
+- [ ] Assign reviewers
+- [ ] Assign assignees
- [ ] Add appropriate test cases
## Remark
From dab27a785c3e6862977b1e79e2cbc5fb332e1a87 Mon Sep 17 00:00:00 2001
From: ginokent <29125616+ginokent@users.noreply.github.com>
Date: Sun, 5 Jan 2025 20:16:29 +0900
Subject: [PATCH 4/4] ci(github-actions): Fix misc
---
.github/workflows/auto-assign.yml | 9 +++------
.github/workflows/label-checker.yml | 6 +++---
.github/workflows/task-list-checker.yml | 5 +++--
3 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/.github/workflows/auto-assign.yml b/.github/workflows/auto-assign.yml
index b379f69..5e39f08 100644
--- a/.github/workflows/auto-assign.yml
+++ b/.github/workflows/auto-assign.yml
@@ -9,15 +9,12 @@ on:
jobs:
auto-assign:
- name: Auto Assign
- if: github.actor != 'dependabot[bot]'
+ if: github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]'
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- if: ${{ toJSON(github.event.pull_request.assignees) == '[]' }}
- run: gh pr edit "${NUMBER}" --add-assignee "${ASSIGNEE}"
env:
GH_TOKEN: ${{ github.token }}
- GH_REPO: ${{ github.repository }}
- NUMBER: ${{ github.event.pull_request.number }}
- ASSIGNEE: ${{ github.event.pull_request.user.login }}
+ run: |
+ gh pr --repo ${{ github.repository }} edit ${{ github.event.pull_request.number }} --add-assignee "${{ github.event.pull_request.user.login }}"
diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml
index a609a2b..7067328 100644
--- a/.github/workflows/label-checker.yml
+++ b/.github/workflows/label-checker.yml
@@ -1,15 +1,15 @@
name: label-checker
-# Dependabot
+# # Dependabot
# gh label create --force "dependencies" --description "Pull requests that update a dependency file" --color 0366D6
# gh label create --force "go" --description "Pull requests that update Go code" --color 16E2E2
# gh label create --force "github_actions" --description "Pull requests that update GitHub Actions code" --color 000000
# gh label create --force "docker" --description "Pull requests that update Docker code" --color 21CEFF
-# Renovate
+# # Renovate
# gh label create --force "renovate" --description "Renovate" --color 009485
-# Commit prefix
+# # Commit prefix
# gh label create --force "BREAKING CHANGE" --description "BREAKING CHANGES" --color FF0303
# gh label create --force "build" --description "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)" --color 5319E7
# gh label create --force "ci" --description "Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)" --color 53C4EE
diff --git a/.github/workflows/task-list-checker.yml b/.github/workflows/task-list-checker.yml
index 7cc1331..38f0181 100644
--- a/.github/workflows/task-list-checker.yml
+++ b/.github/workflows/task-list-checker.yml
@@ -11,12 +11,13 @@ on:
jobs:
task-list-checker:
- if: github.actor != 'dependabot[bot]'
+ if: github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
+ contents: read
pull-requests: read
steps:
- - uses: hakadoriya/github-actions-task-list-checker@main
+ - uses: hakadoriya/github-actions-task-list-checker@v0.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}