Compare commits
73 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ca8cf89de | |||
9b63777a76 | |||
e853b2d5e4 | |||
a88b614e80 | |||
92a48c415d | |||
fe676b70a9 | |||
51bed6bd30 | |||
ac4f583580 | |||
ff1192f09a | |||
459d3cc0e5 | |||
fc2619b757 | |||
fe367372c3 | |||
694a8cf981 | |||
e849e4508b | |||
f8f48d67e0 | |||
ed2b74d436 | |||
0caf48a734 | |||
c4d6402fd9 | |||
83bc0c512b | |||
102e8faf92 | |||
87da0f1169 | |||
b53c49ca28 | |||
47bde8b4f8 | |||
d71de485d6 | |||
964666902f | |||
d5d6d7bf79 | |||
02d10dd08c | |||
4062157544 | |||
a673844fb3 | |||
53248a3a3d | |||
0043a553a7 | |||
13981404f3 | |||
db951d1877 | |||
26c84b3a04 | |||
b3d8cf68f1 | |||
60ae0fed4e | |||
a03e821c02 | |||
592178f066 | |||
260af690ff | |||
7bd12e7a01 | |||
f8a49e033d | |||
3066503a70 | |||
cf899609be | |||
7be0e70754 | |||
8b0ceb759d | |||
7b5cfb2c95 | |||
a4a5b18849 | |||
47583bd955 | |||
018bc7054a | |||
5ca4cb9964 | |||
27bb9a789c | |||
5f7e68d5b7 | |||
da0edc478c | |||
d2be068597 | |||
4113a9a211 | |||
3575262001 | |||
1cc75afc32 | |||
7d72b24770 | |||
ffff60772c | |||
a604b8e375 | |||
2cc3e6c906 | |||
5a475260dd | |||
9c79a26d04 | |||
3fbd87cab1 | |||
5fe5c1d315 | |||
1b4d9b33ef | |||
7598e9148b | |||
89429ac679 | |||
9f81cdfb8a | |||
ab9a7891a7 | |||
58358dd479 | |||
fc13271878 | |||
7cd739ff23 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,5 +1,20 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
#------# custom
|
||||
**/.claude/settings.local.json
|
||||
|
150
.gitlab-ci.yml
150
.gitlab-ci.yml
@ -1,150 +0,0 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||
--volume "$PWD:/code"
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||
artifacts:
|
||||
reports:
|
||||
sast: gl-sast-report.json
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
313
changelog.md
Normal file
313
changelog.md
Normal file
@ -0,0 +1,313 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-05-11 - 3.0.8 - fix(ci)
|
||||
Update CI workflows, build scripts, and export configuration
|
||||
|
||||
- Add separate Gitea workflows for tag and non-tag pushes to automate testing, auditing, and release steps
|
||||
- Revise package.json exports and update dependency versions and build scripts for improved module resolution
|
||||
- Enhance tsconfig settings with baseUrl and paths for consistency
|
||||
- Refine source code formatting and adjust test cases for better maintenance
|
||||
|
||||
## 2024-06-06 - 3.0.7 - no notable changes
|
||||
This release contains no detailed changes.
|
||||
|
||||
## 2024-06-06 - 3.0.6 - core
|
||||
A few fixes and updates were made in this release.
|
||||
|
||||
- fix(core): update
|
||||
- update description
|
||||
|
||||
## 2024-05-17 - 3.0.5 - core
|
||||
A minor core fix was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-05-17 - 3.0.4 - core
|
||||
This release includes several updates to core files and configuration.
|
||||
|
||||
- fix(core): update
|
||||
- update tsconfig
|
||||
- update npmextra.json: githost
|
||||
- update npmextra.json: githost
|
||||
- update npmextra.json: githost
|
||||
|
||||
## 2023-08-08 - 3.0.3 - core
|
||||
A simple core update was performed.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-07-12 - 3.0.2 - core
|
||||
Core updates and a change of organizational scheme were introduced.
|
||||
|
||||
- fix(core): update
|
||||
- switch to new org scheme (x2)
|
||||
|
||||
## 2022-10-26 - 3.0.1 - core
|
||||
A core fix was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2022-07-26 - 3.0.0 - core
|
||||
A minor core update was made.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2022-06-26 - 2.0.44 - core
|
||||
A breaking change switched the module system to esm.
|
||||
|
||||
- BREAKING CHANGE(core): switch to esm
|
||||
|
||||
## 2021-07-21 - 2.0.43 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2021-07-20 - 2.0.42 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2021-07-20 - 2.0.41 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2021-07-20 - 2.0.40 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2021-07-06 - 2.0.39 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-09-08 - 2.0.38 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-09-07 - 2.0.37 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-09-07 - 2.0.36 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-08-02 - 2.0.35 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-11 - 2.0.34 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-11 - 2.0.33 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-11 - 2.0.32 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-11 - 2.0.31 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-11 - 2.0.30 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-11 - 2.0.29 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-11 - 2.0.28 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-08 - 2.0.27 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-08 - 2.0.26 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-08 - 2.0.25 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-08 - 2.0.24 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-07 - 2.0.23 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-05 - 2.0.22 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2020-06-05 - 2.0.21 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-10-22 - 2.0.20 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-10-22 - 2.0.19 - core
|
||||
Dependencies were updated in the core.
|
||||
|
||||
- fix(core): update dependencies
|
||||
|
||||
## 2019-01-30 - 2.0.18 - license
|
||||
License files were updated.
|
||||
|
||||
- fix(license): update license files
|
||||
|
||||
## 2019-01-30 - 2.0.17 - readme
|
||||
A typo in the readme was fixed.
|
||||
|
||||
- fix(readme): fix typo
|
||||
|
||||
## 2019-01-30 - 2.0.16 - readme
|
||||
A typo in the readme was fixed.
|
||||
|
||||
- fix(readme): fix typo
|
||||
|
||||
## 2019-01-28 - 2.0.15 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-01-28 - 2.0.14 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-01-22 - 2.0.13 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-01-22 - 2.0.12 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-01-18 - 2.0.11 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-01-15 - 2.0.10 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2019-01-15 - 2.0.9 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2018-11-11 - 2.0.8 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2018-11-04 - 2.0.7 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2018-11-04 - 2.0.6 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2018-11-04 - 2.0.5 - api
|
||||
An API improvement was made.
|
||||
|
||||
- fix(api): streamline api
|
||||
|
||||
## 2018-11-04 - 2.0.4 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2018-11-03 - 2.0.3 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2018-10-31 - 2.0.2 - core
|
||||
A core update was applied.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2018-10-30 - 2.0.1 - core
|
||||
A new log router was implemented in core.
|
||||
|
||||
- fix(core): implement log router
|
||||
|
||||
## 2018-07-10 - 2.0.0 - core
|
||||
Console enabling was fixed.
|
||||
|
||||
- fix(.enableConsole()): now works
|
||||
|
||||
## 2018-07-10 - 1.0.6 - core
|
||||
A breaking change added a simple defaultLogger to core.
|
||||
|
||||
- BREAKING CHANGE(core): now has simple defaultLogger
|
||||
|
||||
## 2018-07-08 - 1.0.5 - npm
|
||||
Package distribution was fixed.
|
||||
|
||||
- fix(npm): package distribution
|
||||
|
||||
## 2018-06-05 - 1.0.4 - package
|
||||
The package name was updated.
|
||||
|
||||
- fix(package): update package name
|
||||
|
||||
## 2018-06-05 - 1.0.3 - core
|
||||
Several changes were made to update standards and system behavior.
|
||||
|
||||
- fix(core): update to latest standards
|
||||
- system change
|
||||
|
||||
## 2018-01-28 - 1.0.2 - docs
|
||||
Documentation was added to the readme.
|
||||
|
||||
- docs(readme): add readme
|
||||
|
||||
## 2018-01-28 - 1.0.1 - misc
|
||||
Initial cleanup and TypeScript support were introduced.
|
||||
|
||||
- fix(cleanup):
|
||||
- feat(ts): initial
|
||||
|
||||
## 2016-10-15 - 1.0.0 - no notable changes
|
||||
This initial release contains no detailed changes.
|
@ -1,17 +1,37 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartlog",
|
||||
"shortDescription": "minimalistic distributed and extensible logging tool",
|
||||
"npmPackagename": "@pushrocks/smartlog",
|
||||
"description": "A minimalistic, distributed, and extensible logging tool supporting centralized log management.",
|
||||
"npmPackagename": "@push.rocks/smartlog",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
"projectDomain": "push.rocks",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"log management",
|
||||
"typescript",
|
||||
"centralized logging",
|
||||
"json logging",
|
||||
"node.js",
|
||||
"distributed systems",
|
||||
"extensible logging",
|
||||
"log routing",
|
||||
"console logging",
|
||||
"log destinations",
|
||||
"log levels",
|
||||
"error tracking",
|
||||
"development tools"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
||||
}
|
1690
package-lock.json
generated
1690
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
94
package.json
94
package.json
@ -1,35 +1,93 @@
|
||||
{
|
||||
"name": "@pushrocks/smartlog",
|
||||
"version": "2.0.20",
|
||||
"name": "@push.rocks/smartlog",
|
||||
"version": "3.0.8",
|
||||
"private": false,
|
||||
"description": "minimalistic distributed and extensible logging tool",
|
||||
"description": "A minimalistic, distributed, and extensible logging tool supporting centralized log management.",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"log management",
|
||||
"typescript",
|
||||
"centralized logging",
|
||||
"json logging",
|
||||
"scalyr",
|
||||
"elasticsearch",
|
||||
"logdna"
|
||||
"node.js",
|
||||
"distributed systems",
|
||||
"extensible logging",
|
||||
"log routing",
|
||||
"console logging",
|
||||
"log destinations",
|
||||
"log levels",
|
||||
"error tracking",
|
||||
"development tools"
|
||||
],
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist_ts/index.js"
|
||||
},
|
||||
"./context": "./dist_ts_context/index.js",
|
||||
"./interfaces": "./dist_ts_interfaces/index.js",
|
||||
"./source-ora": "./dist_ts_source_ora/index.js",
|
||||
"./destination-clickhouse": "./dist_ts_destination_clickhouse/index.js",
|
||||
"./destination-devtools": "./dist_ts_destination_devtools/index.js",
|
||||
"./destination-file": "./dist_ts_destination_file/index.js",
|
||||
"./destination-local": "./dist_ts_destination_local/index.js",
|
||||
"./destination-receiver": "./dist_ts_destination_receiver/index.js",
|
||||
"./receiver": "./dist_ts_receiver/index.js"
|
||||
},
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
"build": "(tsbuild tsfolders --allowimplicitany && tsbundle npm)",
|
||||
"format": "(gitzone format)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.11.2",
|
||||
"tslint": "^5.20.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@git.zone/tsbuild": "^2.3.2",
|
||||
"@git.zone/tsbundle": "^2.2.5",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^1.0.96",
|
||||
"@push.rocks/tapbundle": "^6.0.3",
|
||||
"@types/node": "^22.15.17"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartlog-interfaces": "^2.0.5"
|
||||
"@api.global/typedrequest-interfaces": "^3.0.19",
|
||||
"@push.rocks/consolecolor": "^2.0.2",
|
||||
"@push.rocks/isounique": "^1.0.4",
|
||||
"@push.rocks/smartclickhouse": "^2.0.17",
|
||||
"@push.rocks/smartfile": "^11.2.0",
|
||||
"@push.rocks/smarthash": "^3.0.4",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smarttime": "^4.1.1",
|
||||
"@push.rocks/webrequest": "^3.0.37",
|
||||
"@tsclass/tsclass": "^9.2.0",
|
||||
"ora": "^8.2.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartlog#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartlog.git"
|
||||
},
|
||||
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
|
||||
"bugs": {
|
||||
"url": "https://code.foss.global/push.rocks/smartlog/issues"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {}
|
||||
}
|
||||
}
|
||||
|
10232
pnpm-lock.yaml
generated
Normal file
10232
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
141
readme.md
141
readme.md
@ -1,77 +1,124 @@
|
||||
# @pushrocks/smartlog
|
||||
# @push.rocks/smartlog
|
||||
|
||||
minimalistic distributed and extensible logging tool
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartlog)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartlog)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartlog)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartlog/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartlog/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartlog/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartlog)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartlog)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
You can install `@push.rocks/smartlog` using npm:
|
||||
|
||||
```sh
|
||||
npm install @push.rocks/smartlog --save
|
||||
```
|
||||
|
||||
Ensure that you have TypeScript and node.js installed in your development environment, as this module is intended to be used with TypeScript.
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
`@push.rocks/smartlog` is a flexible and extensible logging tool designed to provide a minimalistic yet powerful logging solution across different environments, making it especially useful in distributed systems. This documentation aims to guide you through its capabilities, setup, and how to integrate it seamlessly into your TypeScript projects.
|
||||
|
||||
smartlog id s minimal logging package that provides a consistent experience across the complete logging stack. Smartlog allows you to create a logger instance like this:
|
||||
### Creating a Logger Instance
|
||||
|
||||
Start by importing `Smartlog` and create a logger instance by providing a context that describes your logging environment:
|
||||
|
||||
```typescript
|
||||
import { Smartlog } from '@push.rocks/smartlog';
|
||||
|
||||
```ts
|
||||
import { Smartlog } from '@pushrocks/smartlog';
|
||||
const logger = new Smartlog({
|
||||
{
|
||||
logContext: {
|
||||
company: 'My awesome company',
|
||||
companyunit: 'my awesome cloud team',
|
||||
containerName: 'awesome-container',
|
||||
environment: 'kubernetes-production',
|
||||
runtime: 'node',
|
||||
zone: 'zone x'
|
||||
}
|
||||
})
|
||||
|
||||
logger.log('silly', `a silly statement`); // log levels are shown to you by the IDE
|
||||
zone: 'zone x',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
There is also a default logger available that you can use:
|
||||
This context enriches your logs with valuable information, making them easier to filter and analyze in a distributed system.
|
||||
|
||||
```ts
|
||||
import { Smartlog, defaultLogger } from '@pushrocks/smartlog';
|
||||
### Logging Messages
|
||||
|
||||
export class MyAwesomeClass {
|
||||
constructor(public logger: Smartlog = defaultLogger) {
|
||||
// what happens here that a instance of this class will have instance.logger available
|
||||
// if you set a custom logger, than that will be used, if not the default logger.
|
||||
Logging is straightforward; you can log messages at various levels such as `info`, `warn`, `error`, `silly`, etc.:
|
||||
|
||||
```typescript
|
||||
logger.log('info', 'This is an info message');
|
||||
logger.log('error', 'This is an error message with details', { errorCode: 123 });
|
||||
```
|
||||
|
||||
The logging method accepts additional data as the third parameter, allowing you to attach more context to each log message, which is immensely useful for debugging.
|
||||
|
||||
### Using the Default Logger
|
||||
|
||||
For convenience, `@push.rocks/smartlog` provides a default logger that you can use out of the box:
|
||||
|
||||
```typescript
|
||||
import { defaultLogger } from '@push.rocks/smartlog';
|
||||
|
||||
defaultLogger.log('warn', 'This is a warning message using the default logger');
|
||||
```
|
||||
|
||||
This is particularly helpful for simple applications or for initial project setup.
|
||||
|
||||
### Extending With Log Destinations
|
||||
|
||||
One of the core strengths of `@push.rocks/smartlog` is its ability to work with multiple log destinations, enabling you to log messages not just to the console but also to external logging services or custom destinations.
|
||||
|
||||
To add a log destination, you create a class that implements the `ILogDestination` interface and then add it to the logger:
|
||||
|
||||
```typescript
|
||||
import { Smartlog, ILogDestination } from '@push.rocks/smartlog';
|
||||
|
||||
class MyCustomLogDestination implements ILogDestination {
|
||||
async handleLog(logPackage) {
|
||||
// Implement your custom logging logic here
|
||||
console.log(`Custom log: ${logPackage.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const logger = new Smartlog({
|
||||
logContext: {
|
||||
/* your context */
|
||||
},
|
||||
});
|
||||
logger.addLogDestination(new MyCustomLogDestination());
|
||||
```
|
||||
|
||||
### Destinations
|
||||
After adding your custom log destination(s), every log message sent through `Smartlog` will also be routed to them according to their implementation.
|
||||
|
||||
smartlog supports different kinds of destinations.
|
||||
### Integration with Logging Services
|
||||
|
||||
The following destinations are available:
|
||||
`@push.rocks/smartlog` is designed to be extensible; you can integrate it with various logging services like Scalyr, Elasticsearch, LogDNA, etc., by developing or using existing log destinations conforming to those services.
|
||||
|
||||
- [@pushrocks/smartlog-destination-local](https://www.npmjs.com/package/@pushrocks/smartlog-destination-local) - outputs logs to the local console in a colorful, nice to read way.
|
||||
- [@pushrocks/smartlog-destination-devtools](https://www.npmjs.com/package/@pushrocks/smartlog-destination-devtools) - outputs logs into the browser console in a colorful, nice to read way.
|
||||
- [@pushrocks/smartlog-destination-receiver](https://www.npmjs.com/package/@pushrocks/smartlog-destination-receiver) - sends logs to a smartlog receiver (more about that below)
|
||||
- [@mojoio/scalyr](https://www.npmjs.com/package/@pushrocks/smartlog-destination-receiver) - an scalyr API package that comes with a smartlog log destination included
|
||||
- [@mojoio/elasticsearch](https://www.npmjs.com/package/@mojoio/elasticsearch) - an elasticsearch API package that comes with a smartlog destination included
|
||||
Check the npm registry or GitHub for community-contributed log destinations that can seamlessly integrate `@push.rocks/smartlog` into your preferred logging infrastructure.
|
||||
|
||||
### Adding a log destination
|
||||
### Advanced Usage
|
||||
|
||||
```
|
||||
// TBD
|
||||
```
|
||||
- **Log Groups**: You can use log groups to associate related log messages, which is especially handy for tracking logs across distributed systems.
|
||||
- **Custom Log Levels**: Beyond the standard log levels, you can define custom log levels that suit your project needs.
|
||||
- **Dynamic Log Contexts**: The log context can be dynamically adjusted to reflect different stages or aspects of your application logic.
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
### Conclusion
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
`@push.rocks/smartlog` empowers you to implement a robust logging solution tailored to your needs with minimal effort. Its design promotes clarity, flexibility, and integration ease, making it an excellent choice for projects of any scale.
|
||||
|
||||
[](https://push.rocks)
|
||||
Remember to refer to the official documentation and the type definitions for detailed information on all available methods and configurations. Happy logging!
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
0
readme.plan.md
Normal file
0
readme.plan.md
Normal file
48
test/test.browser.ts
Normal file
48
test/test.browser.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartlog from '../ts/index.js';
|
||||
|
||||
let testConsoleLog: smartlog.ConsoleLog;
|
||||
let testSmartLog: smartlog.Smartlog;
|
||||
|
||||
tap.test('should produce a valid ConsoleLog instance', async () => {
|
||||
testConsoleLog = new smartlog.ConsoleLog();
|
||||
testConsoleLog.log('ok', 'this is ok');
|
||||
});
|
||||
|
||||
tap.test('should produce instance of Smartlog', async () => {
|
||||
testSmartLog = new smartlog.Smartlog({
|
||||
logContext: {
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'gitzone',
|
||||
company: 'Lossless GmbH',
|
||||
companyunit: 'Lossless Cloud',
|
||||
containerName: 'testing',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should enable console logging', async () => {
|
||||
testSmartLog.enableConsole({
|
||||
captureAll: true,
|
||||
});
|
||||
console.log('this is a normal log that should be captured');
|
||||
console.log(new Error('hi there'));
|
||||
testSmartLog.log('info', 'this should only be printed once');
|
||||
});
|
||||
|
||||
tap.test('should be able to log things', async () => {
|
||||
testSmartLog.log('silly', 'hi');
|
||||
});
|
||||
|
||||
tap.test('should create a log group', async () => {
|
||||
const logGroup = testSmartLog.createLogGroup('some cool transaction');
|
||||
logGroup.log('info', 'this is logged from a log group');
|
||||
});
|
||||
|
||||
tap.test('should catch error', async () => {
|
||||
console.error(new Error('hey'));
|
||||
// throw new Error('hey');
|
||||
});
|
||||
|
||||
export default tap.start();
|
9
test/test.context.ts
Normal file
9
test/test.context.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartlogContext from '../ts_context/index.js';
|
||||
|
||||
tap.test('should correctly export strings from context module', async () => {
|
||||
expect(typeof smartlogContext.standardExport).toEqual('string');
|
||||
expect(smartlogContext.standardExport).toEqual('Hi there! :) This is an exported string');
|
||||
});
|
||||
|
||||
export default tap.start();
|
19
test/test.destination-clickhouse.node.ts
Normal file
19
test/test.destination-clickhouse.node.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { SmartlogDestinationClickhouse } from '../ts_destination_clickhouse/index.js';
|
||||
import * as smartclickhouse from '@push.rocks/smartclickhouse';
|
||||
|
||||
// Test we can create a destination instance
|
||||
tap.test('should create a ClickHouse destination instance', async () => {
|
||||
// Use mock configuration
|
||||
const clickhouseOptions: smartclickhouse.IClickhouseConstructorOptions = {
|
||||
url: 'defult:@localhost:8123',
|
||||
database: 'test_logs'
|
||||
};
|
||||
|
||||
// Verify we can create an instance
|
||||
// We won't start it to avoid making real connections
|
||||
const clickhouseDestination = new SmartlogDestinationClickhouse(clickhouseOptions);
|
||||
expect(clickhouseDestination).toBeTruthy();
|
||||
});
|
||||
|
||||
export default tap.start();
|
117
test/test.destination-devtools.browser.ts
Normal file
117
test/test.destination-devtools.browser.ts
Normal file
@ -0,0 +1,117 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { SmartlogDestinationDevtools } from '../ts_destination_devtools/index.js';
|
||||
import * as smartlogInterfaces from '../ts_interfaces/index.js';
|
||||
|
||||
let testDestination: SmartlogDestinationDevtools;
|
||||
let originalConsoleLog: any;
|
||||
let consoleLogCalls: any[] = [];
|
||||
|
||||
// Helper to create log package
|
||||
const createMockLogPackage = (level: smartlogInterfaces.TLogLevel, message: string): smartlogInterfaces.ILogPackage => {
|
||||
return {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level,
|
||||
message,
|
||||
context: {
|
||||
environment: 'test',
|
||||
runtime: 'chrome'
|
||||
},
|
||||
correlation: {
|
||||
id: '123',
|
||||
type: 'none'
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Tests
|
||||
tap.test('should setup test environment', async () => {
|
||||
// Save original console.log
|
||||
originalConsoleLog = console.log;
|
||||
|
||||
// Replace with mock
|
||||
console.log = (...args: any[]) => {
|
||||
consoleLogCalls.push(args);
|
||||
// Don't call original to avoid polluting test output
|
||||
};
|
||||
});
|
||||
|
||||
tap.test('should create a devtools destination instance', async () => {
|
||||
testDestination = new SmartlogDestinationDevtools();
|
||||
expect(testDestination).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should log error level messages with appropriate styling', async () => {
|
||||
consoleLogCalls = [];
|
||||
|
||||
const logPackage = createMockLogPackage('error', 'Test error message');
|
||||
await testDestination.handleLog(logPackage);
|
||||
|
||||
expect(consoleLogCalls.length).toEqual(1);
|
||||
expect(consoleLogCalls[0][0]).toContain('Error:');
|
||||
expect(consoleLogCalls[0][1]).toContain('background:#000000;color:#800000;');
|
||||
expect(consoleLogCalls[0][2]).toContain('Test error message');
|
||||
});
|
||||
|
||||
tap.test('should log info level messages with appropriate styling', async () => {
|
||||
consoleLogCalls = [];
|
||||
|
||||
const logPackage = createMockLogPackage('info', 'Test info message');
|
||||
await testDestination.handleLog(logPackage);
|
||||
|
||||
expect(consoleLogCalls.length).toEqual(1);
|
||||
expect(consoleLogCalls[0][0]).toContain('Info:');
|
||||
expect(consoleLogCalls[0][1]).toContain('background:#EC407A;color:#ffffff;');
|
||||
expect(consoleLogCalls[0][2]).toContain('Test info message');
|
||||
});
|
||||
|
||||
tap.test('should log ok level messages with appropriate styling', async () => {
|
||||
consoleLogCalls = [];
|
||||
|
||||
const logPackage = createMockLogPackage('ok', 'Test ok message');
|
||||
await testDestination.handleLog(logPackage);
|
||||
|
||||
expect(consoleLogCalls.length).toEqual(1);
|
||||
expect(consoleLogCalls[0][0]).toContain('OK:');
|
||||
expect(consoleLogCalls[0][2]).toContain('Test ok message');
|
||||
});
|
||||
|
||||
tap.test('should log success level messages with appropriate styling', async () => {
|
||||
consoleLogCalls = [];
|
||||
|
||||
const logPackage = createMockLogPackage('success', 'Test success message');
|
||||
await testDestination.handleLog(logPackage);
|
||||
|
||||
expect(consoleLogCalls.length).toEqual(1);
|
||||
expect(consoleLogCalls[0][0]).toContain('Success:');
|
||||
expect(consoleLogCalls[0][2]).toContain('Test success message');
|
||||
});
|
||||
|
||||
tap.test('should log warn level messages with appropriate styling', async () => {
|
||||
consoleLogCalls = [];
|
||||
|
||||
const logPackage = createMockLogPackage('warn', 'Test warning message');
|
||||
await testDestination.handleLog(logPackage);
|
||||
|
||||
expect(consoleLogCalls.length).toEqual(1);
|
||||
expect(consoleLogCalls[0][0]).toContain('Warn:');
|
||||
expect(consoleLogCalls[0][2]).toContain('Test warning message');
|
||||
});
|
||||
|
||||
tap.test('should log note level messages with appropriate styling', async () => {
|
||||
consoleLogCalls = [];
|
||||
|
||||
const logPackage = createMockLogPackage('note', 'Test note message');
|
||||
await testDestination.handleLog(logPackage);
|
||||
|
||||
expect(consoleLogCalls.length).toEqual(1);
|
||||
expect(consoleLogCalls[0][0]).toContain('Note:');
|
||||
expect(consoleLogCalls[0][2]).toContain('Test note message');
|
||||
});
|
||||
|
||||
tap.test('should clean up test environment', async () => {
|
||||
// Restore the original console.log
|
||||
console.log = originalConsoleLog;
|
||||
});
|
||||
|
||||
export default tap.start();
|
10
test/test.destination-devtools.node.ts
Normal file
10
test/test.destination-devtools.node.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { SmartlogDestinationDevtools } from '../ts_destination_devtools/index.js';
|
||||
|
||||
// Test we can create a destination instance
|
||||
tap.test('should create a DevTools destination instance', async () => {
|
||||
const devtoolsDestination = new SmartlogDestinationDevtools();
|
||||
expect(devtoolsDestination).toBeTruthy();
|
||||
});
|
||||
|
||||
export default tap.start();
|
87
test/test.destination-file.node.ts
Normal file
87
test/test.destination-file.node.ts
Normal file
@ -0,0 +1,87 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { SmartlogDestinationFile } from '../ts_destination_file/index.js';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
let testLogDir: string;
|
||||
let testLogFile: string;
|
||||
let testDestination: SmartlogDestinationFile;
|
||||
|
||||
// Setup and teardown helpers
|
||||
const createTempLogDir = () => {
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'smartlog-test-'));
|
||||
return tempDir;
|
||||
};
|
||||
|
||||
const removeTempDir = (dirPath: string) => {
|
||||
if (fs.existsSync(dirPath)) {
|
||||
const files = fs.readdirSync(dirPath);
|
||||
for (const file of files) {
|
||||
fs.unlinkSync(path.join(dirPath, file));
|
||||
}
|
||||
fs.rmdirSync(dirPath);
|
||||
}
|
||||
};
|
||||
|
||||
// Tests
|
||||
tap.test('should prepare test environment', async () => {
|
||||
testLogDir = createTempLogDir();
|
||||
testLogFile = path.join(testLogDir, 'test.log');
|
||||
expect(fs.existsSync(testLogDir)).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should create a file destination instance with a valid path', async () => {
|
||||
testDestination = new SmartlogDestinationFile(testLogFile);
|
||||
expect(testDestination).toBeTruthy();
|
||||
expect(fs.existsSync(testLogFile)).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should throw error when file path is not absolute', async () => {
|
||||
let errorThrown = false;
|
||||
try {
|
||||
new SmartlogDestinationFile('relative/path/file.log');
|
||||
} catch (error) {
|
||||
errorThrown = true;
|
||||
expect(error.message).toContain('filePath needs to be absolute');
|
||||
}
|
||||
expect(errorThrown).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should write log messages to file', async () => {
|
||||
const testMessage = 'Test log message';
|
||||
|
||||
await testDestination.handleLog({
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level: 'info',
|
||||
message: testMessage,
|
||||
context: {
|
||||
environment: 'test',
|
||||
runtime: 'node'
|
||||
},
|
||||
correlation: {
|
||||
id: '123',
|
||||
type: 'none'
|
||||
}
|
||||
});
|
||||
|
||||
// Give file system a moment to write
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
|
||||
const fileContent = fs.readFileSync(testLogFile, 'utf8');
|
||||
expect(fileContent).toContain(testMessage);
|
||||
});
|
||||
|
||||
tap.test('should clean up test resources', async () => {
|
||||
// Close file handle before cleanup
|
||||
testDestination.fileWriteStream.end();
|
||||
|
||||
// Small delay to ensure file is properly closed
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
removeTempDir(testLogDir);
|
||||
expect(fs.existsSync(testLogDir)).toBeFalse();
|
||||
});
|
||||
|
||||
export default tap.start();
|
96
test/test.destination-local.node.ts
Normal file
96
test/test.destination-local.node.ts
Normal file
@ -0,0 +1,96 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { DestinationLocal } from '../ts_destination_local/index.js';
|
||||
import * as smartlogInterfaces from '../ts_interfaces/index.js';
|
||||
|
||||
let testDestination: DestinationLocal;
|
||||
|
||||
// Mock log package
|
||||
const createMockLogPackage = (level: smartlogInterfaces.TLogLevel, message: string): smartlogInterfaces.ILogPackage => {
|
||||
return {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level,
|
||||
message,
|
||||
context: {
|
||||
environment: 'test',
|
||||
runtime: 'node'
|
||||
},
|
||||
correlation: {
|
||||
id: '123',
|
||||
type: 'none'
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Tests
|
||||
tap.test('should create a local destination instance', async () => {
|
||||
testDestination = new DestinationLocal();
|
||||
expect(testDestination).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should handle logs with different levels', async () => {
|
||||
// Testing with a spy would be ideal, but since we don't have a mocking framework,
|
||||
// we'll just verify the method runs without errors for different log levels
|
||||
|
||||
// Test info level
|
||||
const logPackageInfo = createMockLogPackage('info', 'Info message');
|
||||
await testDestination.handleLog(logPackageInfo);
|
||||
|
||||
// Test error level
|
||||
const logPackageError = createMockLogPackage('error', 'Error message');
|
||||
await testDestination.handleLog(logPackageError);
|
||||
|
||||
// Test warn level
|
||||
const logPackageWarn = createMockLogPackage('warn', 'Warning message');
|
||||
await testDestination.handleLog(logPackageWarn);
|
||||
|
||||
// Test silly level
|
||||
const logPackageSilly = createMockLogPackage('silly', 'Silly message');
|
||||
await testDestination.handleLog(logPackageSilly);
|
||||
});
|
||||
|
||||
tap.test('should handle reduced logging', async () => {
|
||||
testDestination = new DestinationLocal();
|
||||
|
||||
// Note: In a real test environment with a mocking framework,
|
||||
// we would capture console output and verify it's only written
|
||||
// according to the expected behavior. Here we just ensure
|
||||
// the methods execute without errors.
|
||||
|
||||
// First call with message
|
||||
testDestination.logReduced('Test message');
|
||||
|
||||
// Same message immediately after
|
||||
testDestination.logReduced('Test message');
|
||||
|
||||
// Different message
|
||||
testDestination.logReduced('Different message');
|
||||
});
|
||||
|
||||
tap.test('should handle repeated logging with repeatEveryTimesArg', async () => {
|
||||
testDestination = new DestinationLocal();
|
||||
|
||||
// First call with message
|
||||
testDestination.logReduced('Repeated with count', 3);
|
||||
|
||||
// Second call
|
||||
testDestination.logReduced('Repeated with count', 3);
|
||||
|
||||
// Third call
|
||||
testDestination.logReduced('Repeated with count', 3);
|
||||
|
||||
// Fourth call (3rd repetition)
|
||||
testDestination.logReduced('Repeated with count', 3);
|
||||
});
|
||||
|
||||
tap.test('should create new line(s)', async () => {
|
||||
testDestination = new DestinationLocal();
|
||||
|
||||
// Default 1 line
|
||||
testDestination.newLine();
|
||||
|
||||
// Multiple lines
|
||||
testDestination.newLine(3);
|
||||
});
|
||||
|
||||
export default tap.start();
|
72
test/test.destination-receiver.node.ts
Normal file
72
test/test.destination-receiver.node.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { SmartlogDestinationReceiver } from '../ts_destination_receiver/index.js';
|
||||
import { Smartlog } from '../ts/index.js';
|
||||
import * as smartlogInterfaces from '../ts_interfaces/index.js';
|
||||
|
||||
let testDestination: SmartlogDestinationReceiver;
|
||||
let testSmartlog: Smartlog;
|
||||
|
||||
// Mock log package
|
||||
const createMockLogPackage = (level: smartlogInterfaces.TLogLevel, message: string): smartlogInterfaces.ILogPackage => {
|
||||
return {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level,
|
||||
message,
|
||||
context: {
|
||||
environment: 'test',
|
||||
runtime: 'node'
|
||||
},
|
||||
correlation: {
|
||||
id: '123',
|
||||
type: 'none'
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Tests
|
||||
tap.test('should create a Smartlog instance', async () => {
|
||||
testSmartlog = new Smartlog({
|
||||
logContext: {
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'test-zone',
|
||||
company: 'Test Company',
|
||||
companyunit: 'Test Unit',
|
||||
containerName: 'test-container',
|
||||
},
|
||||
});
|
||||
|
||||
expect(testSmartlog).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should create a destination receiver instance with valid options', async () => {
|
||||
testDestination = new SmartlogDestinationReceiver({
|
||||
passphrase: 'test-passphrase',
|
||||
receiverEndpoint: 'https://example.com/logs',
|
||||
});
|
||||
|
||||
expect(testDestination).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should attempt to send logs to the receiver endpoint', async () => {
|
||||
// Create a mock version of the webrequest.postJson method to avoid actual HTTP calls
|
||||
const originalPostJson = testDestination['webrequest'].postJson;
|
||||
testDestination['webrequest'].postJson = async () => {
|
||||
return {
|
||||
body: { status: 'ok' },
|
||||
statusCode: 200
|
||||
};
|
||||
};
|
||||
|
||||
try {
|
||||
const logPackage = createMockLogPackage('info', 'Test receiver message');
|
||||
const result = await testDestination.handleLog(logPackage);
|
||||
expect(result).toEqual({ status: 'ok' });
|
||||
} finally {
|
||||
// Restore the original method
|
||||
testDestination['webrequest'].postJson = originalPostJson;
|
||||
}
|
||||
});
|
||||
|
||||
export default tap.start();
|
115
test/test.receiver.node.ts
Normal file
115
test/test.receiver.node.ts
Normal file
@ -0,0 +1,115 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { SmartlogReceiver } from '../ts_receiver/index.js';
|
||||
import { Smartlog } from '../ts/index.js';
|
||||
import * as smartlogInterfaces from '../ts_interfaces/index.js';
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
|
||||
let testSmartlog: Smartlog;
|
||||
let testReceiver: SmartlogReceiver;
|
||||
const testPassphrase = 'test-secret-passphrase';
|
||||
|
||||
// Helper to create authenticated log package
|
||||
const createAuthenticatedLogPackage = (
|
||||
level: smartlogInterfaces.TLogLevel,
|
||||
message: string
|
||||
): smartlogInterfaces.ILogPackageAuthenticated => {
|
||||
const logPackage: smartlogInterfaces.ILogPackage = {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level,
|
||||
message,
|
||||
context: {
|
||||
environment: 'test',
|
||||
runtime: 'node'
|
||||
},
|
||||
correlation: {
|
||||
id: '123',
|
||||
type: 'none'
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
auth: smarthash.sha256FromStringSync(testPassphrase),
|
||||
logPackage
|
||||
};
|
||||
};
|
||||
|
||||
// Tests
|
||||
tap.test('should create a Smartlog instance for receiver', async () => {
|
||||
testSmartlog = new Smartlog({
|
||||
logContext: {
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'test-zone',
|
||||
company: 'Test Company',
|
||||
companyunit: 'Test Unit',
|
||||
containerName: 'test-container',
|
||||
},
|
||||
});
|
||||
|
||||
expect(testSmartlog).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should create a SmartlogReceiver instance', async () => {
|
||||
// Create a validator function that always returns true
|
||||
const validatorFunction = async () => true;
|
||||
|
||||
testReceiver = new SmartlogReceiver({
|
||||
smartlogInstance: testSmartlog,
|
||||
passphrase: testPassphrase,
|
||||
validatorFunction
|
||||
});
|
||||
|
||||
expect(testReceiver).toBeTruthy();
|
||||
expect(testReceiver.passphrase).toEqual(testPassphrase);
|
||||
});
|
||||
|
||||
tap.test('should handle authenticated log with correct passphrase', async () => {
|
||||
const authLogPackage = createAuthenticatedLogPackage('info', 'Test authenticated message');
|
||||
|
||||
const result = await testReceiver.handleAuthenticatedLog(authLogPackage);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
expect(result.status).toEqual('ok');
|
||||
});
|
||||
|
||||
tap.test('should reject authenticated log with incorrect passphrase', async () => {
|
||||
const logPackage: smartlogInterfaces.ILogPackage = {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level: 'info',
|
||||
message: 'Test unauthorized message',
|
||||
context: {
|
||||
environment: 'test',
|
||||
runtime: 'node'
|
||||
},
|
||||
correlation: {
|
||||
id: '123',
|
||||
type: 'none'
|
||||
}
|
||||
};
|
||||
|
||||
const badAuthPackage = {
|
||||
auth: 'incorrect-hash',
|
||||
logPackage
|
||||
};
|
||||
|
||||
const result = await testReceiver.handleAuthenticatedLog(badAuthPackage);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
expect(result.status).toEqual('error');
|
||||
});
|
||||
|
||||
tap.test('should handle many authenticated logs', async () => {
|
||||
const authLogPackage1 = createAuthenticatedLogPackage('info', 'Test batch message 1');
|
||||
const authLogPackage2 = createAuthenticatedLogPackage('warn', 'Test batch message 2');
|
||||
const authLogPackage3 = createAuthenticatedLogPackage('error', 'Test batch message 3');
|
||||
|
||||
const authLogPackages = [authLogPackage1, authLogPackage2, authLogPackage3];
|
||||
|
||||
await testReceiver.handleManyAuthenticatedLogs(authLogPackages);
|
||||
|
||||
// No assertions needed as we're just testing it doesn't throw errors
|
||||
});
|
||||
|
||||
export default tap.start();
|
75
test/test.source-ora.node.ts
Normal file
75
test/test.source-ora.node.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { SmartlogSourceOra } from '../ts_source_ora/index.js';
|
||||
|
||||
let testSourceOra: SmartlogSourceOra;
|
||||
|
||||
tap.test('should create a SmartlogSourceOra instance', async () => {
|
||||
testSourceOra = new SmartlogSourceOra();
|
||||
expect(testSourceOra).toBeTruthy();
|
||||
expect(testSourceOra.started).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('should set text and start spinner', async () => {
|
||||
const testText = 'Testing ora spinner';
|
||||
testSourceOra.text(testText);
|
||||
|
||||
expect(testSourceOra.started).toBeTrue();
|
||||
expect(testSourceOra.oraInstance.text).toEqual(testText);
|
||||
});
|
||||
|
||||
tap.test('should update text', async () => {
|
||||
const newText = 'Updated text';
|
||||
testSourceOra.text(newText);
|
||||
|
||||
expect(testSourceOra.oraInstance.text).toEqual(newText);
|
||||
expect(testSourceOra.started).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should stop spinner', async () => {
|
||||
testSourceOra.stop();
|
||||
// We can't easily test the visual state, but we can verify it doesn't throw errors
|
||||
});
|
||||
|
||||
tap.test('should finish with success', async () => {
|
||||
testSourceOra = new SmartlogSourceOra();
|
||||
testSourceOra.text('Starting again');
|
||||
|
||||
const successText = 'Operation successful';
|
||||
testSourceOra.finishSuccess(successText);
|
||||
|
||||
expect(testSourceOra.started).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('should finish with failure', async () => {
|
||||
testSourceOra = new SmartlogSourceOra();
|
||||
testSourceOra.text('Starting again');
|
||||
|
||||
const failText = 'Operation failed';
|
||||
testSourceOra.finishFail(failText);
|
||||
|
||||
expect(testSourceOra.started).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('should handle success and next', async () => {
|
||||
testSourceOra = new SmartlogSourceOra();
|
||||
testSourceOra.text('Starting again');
|
||||
|
||||
const nextText = 'Next operation';
|
||||
testSourceOra.successAndNext(nextText);
|
||||
|
||||
expect(testSourceOra.started).toBeTrue();
|
||||
expect(testSourceOra.oraInstance.text).toEqual(nextText);
|
||||
});
|
||||
|
||||
tap.test('should handle fail and next', async () => {
|
||||
testSourceOra = new SmartlogSourceOra();
|
||||
testSourceOra.text('Starting again');
|
||||
|
||||
const nextText = 'Next operation after failure';
|
||||
testSourceOra.failAndNext(nextText);
|
||||
|
||||
expect(testSourceOra.started).toBeTrue();
|
||||
expect(testSourceOra.oraInstance.text).toEqual(nextText);
|
||||
});
|
||||
|
||||
export default tap.start();
|
45
test/test.ts
45
test/test.ts
@ -1,19 +1,48 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartlog from '../ts/index';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartlog from '../ts/index.js';
|
||||
|
||||
let defaultLogger: smartlog.Smartlog;
|
||||
let testConsoleLog: smartlog.ConsoleLog;
|
||||
let testSmartLog: smartlog.Smartlog;
|
||||
|
||||
tap.test('should produce a valid ConsoleLog instance', async () => {
|
||||
testConsoleLog = new smartlog.ConsoleLog();
|
||||
testConsoleLog.log('ok', 'this is ok');
|
||||
});
|
||||
|
||||
tap.test('should produce instance of Smartlog', async () => {
|
||||
defaultLogger = smartlog.defaultLogger;
|
||||
expect(defaultLogger).to.be.instanceOf(smartlog.Smartlog);
|
||||
testSmartLog = new smartlog.Smartlog({
|
||||
logContext: {
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'gitzone',
|
||||
company: 'Lossless GmbH',
|
||||
companyunit: 'Lossless Cloud',
|
||||
containerName: 'testing',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should enable console logging', async () => {
|
||||
defaultLogger.enableConsole();
|
||||
testSmartLog.enableConsole({
|
||||
captureAll: true,
|
||||
});
|
||||
console.log('this is a normal log that should be captured');
|
||||
console.log(new Error('hi there'));
|
||||
testSmartLog.log('info', 'this should only be printed once');
|
||||
});
|
||||
|
||||
tap.test('should be able to log things', async () => {
|
||||
defaultLogger.log('silly', 'hi');
|
||||
testSmartLog.log('silly', 'hi');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
tap.test('should create a log group', async () => {
|
||||
const logGroup = testSmartLog.createLogGroup('some cool transaction');
|
||||
logGroup.log('info', 'this is logged from a log group');
|
||||
});
|
||||
|
||||
tap.test('should catch error', async () => {
|
||||
console.error(new Error('hey'));
|
||||
// throw new Error('hey');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog',
|
||||
version: '3.0.8',
|
||||
description: 'A minimalistic, distributed, and extensible logging tool supporting centralized log management.'
|
||||
}
|
20
ts/index.ts
20
ts/index.ts
@ -1,16 +1,6 @@
|
||||
import * as plugins from './smartlog.plugins';
|
||||
import { Smartlog } from './smartlog.classes.smartlog';
|
||||
const defaultLogger: Smartlog = new Smartlog({
|
||||
logContext: {
|
||||
company: 'undefined',
|
||||
companyunit: 'undefefined',
|
||||
containerName: 'undefined',
|
||||
environment: 'local',
|
||||
runtime: 'node',
|
||||
zone: 'undefined'
|
||||
}
|
||||
});
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
import { ConsoleLog } from './smartlog.classes.consolelog.js';
|
||||
import { LogGroup } from './smartlog.classes.loggroup.js';
|
||||
import { Smartlog } from './smartlog.classes.smartlog.js';
|
||||
|
||||
defaultLogger.enableConsole();
|
||||
|
||||
export { Smartlog, defaultLogger };
|
||||
export { ConsoleLog, LogGroup, Smartlog };
|
||||
|
15
ts/smartlog.classes.consolelog.ts
Normal file
15
ts/smartlog.classes.consolelog.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
|
||||
/**
|
||||
* a console log optimized for smartlog
|
||||
*/
|
||||
export class ConsoleLog {
|
||||
public log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
dataArg?: any,
|
||||
correlationArg?: plugins.smartlogInterfaces.ILogCorrelation,
|
||||
) {
|
||||
console.log(`__# ${logLevelArg}: ${logMessageArg}`);
|
||||
}
|
||||
}
|
27
ts/smartlog.classes.loggroup.ts
Normal file
27
ts/smartlog.classes.loggroup.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
import { Smartlog } from './smartlog.classes.smartlog.js';
|
||||
|
||||
export class LogGroup {
|
||||
public smartlogRef: Smartlog;
|
||||
public transactionId: string;
|
||||
public groupId = plugins.isounique.uni();
|
||||
|
||||
constructor(smartlogInstance: Smartlog, transactionIdArg: string) {
|
||||
this.smartlogRef = smartlogInstance;
|
||||
this.transactionId = transactionIdArg;
|
||||
}
|
||||
|
||||
public log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
logDataArg?: any,
|
||||
) {
|
||||
this.smartlogRef.log(logLevelArg, logMessageArg, logDataArg, {
|
||||
id: plugins.isounique.uni(),
|
||||
type: 'none',
|
||||
group: this.groupId,
|
||||
instance: this.smartlogRef.uniInstanceId,
|
||||
transaction: this.transactionId,
|
||||
});
|
||||
}
|
||||
}
|
@ -1,23 +1,21 @@
|
||||
import * as plugins from './smartlog.plugins';
|
||||
|
||||
import { ILogDestination, ILogPackage } from '@pushrocks/smartlog-interfaces';
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
|
||||
export class LogRouter {
|
||||
/**
|
||||
* all log destinations
|
||||
*/
|
||||
private logDestinations: ILogDestination[] = [];
|
||||
private logDestinations: plugins.smartlogInterfaces.ILogDestination[] = [];
|
||||
|
||||
constructor() {}
|
||||
|
||||
public addLogDestination(logDestination: ILogDestination) {
|
||||
public addLogDestination(logDestination: plugins.smartlogInterfaces.ILogDestination) {
|
||||
this.logDestinations.push(logDestination);
|
||||
}
|
||||
|
||||
// routes the log according to added logDestinations
|
||||
routeLog(logPackageArg: ILogPackage) {
|
||||
public async routeLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
for (const logDestination of this.logDestinations) {
|
||||
logDestination.handleLog(logPackageArg);
|
||||
await logDestination.handleLog(logPackageArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,30 @@
|
||||
import * as plugins from './smartlog.plugins';
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
|
||||
import { LogRouter } from './smartlog.classes.logrouter';
|
||||
import { LogRouter } from './smartlog.classes.logrouter.js';
|
||||
import { LogGroup } from './smartlog.classes.loggroup.js';
|
||||
|
||||
export interface ISmartlogContructorOptions {
|
||||
logContext: plugins.smartlogInterfaces.ILogContext;
|
||||
minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;
|
||||
}
|
||||
|
||||
export class Smartlog {
|
||||
private logContext: plugins.smartlogInterfaces.ILogContext;
|
||||
private minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
|
||||
export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
// STATIC
|
||||
public static createForCommitinfo(
|
||||
commitinfo: plugins.smartlogInterfaces.ILogContext['commitinfo'],
|
||||
) {
|
||||
return new Smartlog({
|
||||
logContext: {
|
||||
commitinfo,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public logContext: plugins.smartlogInterfaces.ILogContext;
|
||||
public minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
|
||||
|
||||
public uniInstanceId: string = plugins.isounique.uni();
|
||||
|
||||
private consoleEnabled: boolean;
|
||||
|
||||
@ -21,7 +36,7 @@ export class Smartlog {
|
||||
|
||||
constructor(optionsArg: ISmartlogContructorOptions) {
|
||||
this.logContext = optionsArg.logContext;
|
||||
this.minimumLogLevel = optionsArg.minimumLogLevel;
|
||||
this.minimumLogLevel = optionsArg.minimumLogLevel || 'silly';
|
||||
}
|
||||
|
||||
// ============
|
||||
@ -31,7 +46,40 @@ export class Smartlog {
|
||||
/**
|
||||
* enables console logging
|
||||
*/
|
||||
public enableConsole() {
|
||||
public enableConsole(optionsArg?: { captureAll: boolean }) {
|
||||
if (globalThis.process && optionsArg && optionsArg.captureAll) {
|
||||
const process = globalThis.process;
|
||||
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
||||
|
||||
process.stdout.write = (...args: any) => {
|
||||
const logString: string = args[0];
|
||||
if (!logString || typeof logString !== 'string') {
|
||||
// continue as planned
|
||||
return originalStdoutWrite(...args);
|
||||
}
|
||||
|
||||
if (!logString.startsWith('LOG')) {
|
||||
if (logString.includes('Error:')) {
|
||||
this.log('error', logString);
|
||||
} else {
|
||||
this.log('info', logString);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return originalStdoutWrite(...args);
|
||||
};
|
||||
|
||||
process.stderr.write = (...args: any) => {
|
||||
const logString: string = args[0];
|
||||
if (!logString || typeof logString !== 'string' || !logString.startsWith('LOG')) {
|
||||
this.log('error', logString);
|
||||
return true;
|
||||
}
|
||||
return originalStderrWrite(...args);
|
||||
};
|
||||
}
|
||||
this.consoleEnabled = true;
|
||||
}
|
||||
|
||||
@ -43,40 +91,74 @@ export class Smartlog {
|
||||
* @param logLevelArg - the log level
|
||||
* @param logMessageArg - the log message
|
||||
* @param logDataArg - any additional log data
|
||||
* @param correlationArg - info about corrleations
|
||||
*/
|
||||
public log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string, logDataArg?: any) {
|
||||
public async log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
logDataArg?: any,
|
||||
correlationArg?: plugins.smartlogInterfaces.ILogCorrelation,
|
||||
) {
|
||||
correlationArg = {
|
||||
...{
|
||||
id: plugins.isounique.uni(),
|
||||
type: 'none',
|
||||
instance: this.uniInstanceId,
|
||||
},
|
||||
...correlationArg,
|
||||
};
|
||||
|
||||
if (this.consoleEnabled) {
|
||||
console.log(
|
||||
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLevelArg}: ${logMessageArg}`
|
||||
);
|
||||
this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);
|
||||
}
|
||||
|
||||
const logPackage: plugins.smartlogInterfaces.ILogPackage = {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
context: this.logContext,
|
||||
level: logLevelArg,
|
||||
message: logMessageArg
|
||||
correlation: correlationArg,
|
||||
message: logMessageArg,
|
||||
};
|
||||
if (logDataArg) {
|
||||
logPackage.data = logDataArg;
|
||||
}
|
||||
this.logRouter.routeLog(logPackage);
|
||||
await this.logRouter.routeLog(logPackage);
|
||||
}
|
||||
|
||||
public increment(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg) {
|
||||
public increment(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
logDataArg?: any,
|
||||
correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
|
||||
id: plugins.isounique.uni(),
|
||||
type: 'none',
|
||||
},
|
||||
) {
|
||||
if (this.consoleEnabled) {
|
||||
console.log(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
|
||||
this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
|
||||
}
|
||||
this.logRouter.routeLog({
|
||||
timestamp: Date.now(),
|
||||
type: 'increment',
|
||||
context: this.logContext,
|
||||
level: logLevelArg,
|
||||
message: logMessageArg
|
||||
message: logMessageArg,
|
||||
correlation: correlationArg,
|
||||
});
|
||||
}
|
||||
|
||||
public handleLogPackage(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
this.logRouter.routeLog(logPackageArg);
|
||||
public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
await this.logRouter.routeLog(logPackageArg);
|
||||
}
|
||||
|
||||
private safeConsoleLog(logLine: string) {
|
||||
console.log(
|
||||
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`,
|
||||
);
|
||||
}
|
||||
|
||||
public createLogGroup(transactionId: string = 'none') {
|
||||
return new LogGroup(this, transactionId);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
|
||||
import * as isounique from '@push.rocks/isounique';
|
||||
import * as smartlogInterfaces from '../dist_ts_interfaces/index.js';
|
||||
|
||||
export {
|
||||
smartlogInterfaces
|
||||
};
|
||||
export { isounique, smartlogInterfaces };
|
||||
|
3
ts_context/index.ts
Normal file
3
ts_context/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as plugins from './smartlog-context.plugins.js';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
6
ts_context/smartlog-context.plugins.ts
Normal file
6
ts_context/smartlog-context.plugins.ts
Normal file
@ -0,0 +1,6 @@
|
||||
// node native scope
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
path
|
||||
}
|
8
ts_destination_clickhouse/00_commitinfo_data.ts
Normal file
8
ts_destination_clickhouse/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog-destination-clickhouse',
|
||||
version: '1.0.14',
|
||||
description: 'A library to integrate Smartlog logging with ClickHouse database for efficient log storage and querying.'
|
||||
}
|
30
ts_destination_clickhouse/index.ts
Normal file
30
ts_destination_clickhouse/index.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import * as plugins from './slclick.plugins.js';
|
||||
|
||||
export class SmartlogDestinationClickhouse implements plugins.smartlogInterfaces.ILogDestination {
|
||||
// STATIC
|
||||
public static async createAndStart(
|
||||
optionsArg: plugins.smartclickhouse.IClickhouseConstructorOptions
|
||||
) {
|
||||
const destinationClickhouse = new SmartlogDestinationClickhouse(optionsArg);
|
||||
await destinationClickhouse.start();
|
||||
return destinationClickhouse;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
private smartclickhouseDb: plugins.smartclickhouse.SmartClickHouseDb;
|
||||
private logTable: plugins.smartclickhouse.TimeDataTable;
|
||||
constructor(options: plugins.smartclickhouse.IClickhouseConstructorOptions) {
|
||||
this.smartclickhouseDb = new plugins.smartclickhouse.SmartClickHouseDb(options);
|
||||
}
|
||||
|
||||
public async start() {
|
||||
await this.smartclickhouseDb.start();
|
||||
this.logTable = await this.smartclickhouseDb.getTable('logs');
|
||||
}
|
||||
|
||||
public async handleLog(
|
||||
logPackage: plugins.smartlogInterfaces.ILogPackage<unknown>
|
||||
): Promise<void> {
|
||||
await this.logTable.addData(logPackage);
|
||||
}
|
||||
}
|
5
ts_destination_clickhouse/slclick.plugins.ts
Normal file
5
ts_destination_clickhouse/slclick.plugins.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// pushrocks scope
|
||||
import * as smartlogInterfaces from '../dist_ts_interfaces/index.js';
|
||||
import * as smartclickhouse from '@push.rocks/smartclickhouse';
|
||||
|
||||
export { smartlogInterfaces, smartclickhouse };
|
8
ts_destination_devtools/00_commitinfo_data.ts
Normal file
8
ts_destination_devtools/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog-destination-devtools',
|
||||
version: '1.0.12',
|
||||
description: 'A library enabling enhanced logging in browser development tools.'
|
||||
}
|
58
ts_destination_devtools/index.ts
Normal file
58
ts_destination_devtools/index.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import type { ILogDestination, ILogPackage } from '../dist_ts_interfaces/index.js';
|
||||
|
||||
export class SmartlogDestinationDevtools implements ILogDestination {
|
||||
public async handleLog(logPackageArg: ILogPackage) {
|
||||
await this.logInBrowser(logPackageArg);
|
||||
}
|
||||
|
||||
private async logInBrowser(logPackage: ILogPackage) {
|
||||
switch (logPackage.level) {
|
||||
case 'error':
|
||||
console.log(
|
||||
`%c Error: %c ${logPackage.message}`,
|
||||
'background:#000000;color:#800000;',
|
||||
'color:#000000;'
|
||||
);
|
||||
break;
|
||||
case 'info':
|
||||
console.log(
|
||||
`%c Info: %c ${logPackage.message}`,
|
||||
'background:#EC407A;color:#ffffff;',
|
||||
'color:#EC407A;'
|
||||
);
|
||||
break;
|
||||
case 'ok':
|
||||
console.log(
|
||||
`%c OK: %c ${logPackage.message}`,
|
||||
'background:#000000;color:#8BC34A;',
|
||||
'color:#000000;'
|
||||
);
|
||||
break;
|
||||
case 'success':
|
||||
console.log(
|
||||
`%c Success: %c ${logPackage.message}`,
|
||||
'background:#8BC34A;color:#ffffff;',
|
||||
'color:#8BC34A;'
|
||||
);
|
||||
break;
|
||||
case 'warn':
|
||||
console.log(
|
||||
`%c Warn: %c ${logPackage.message}`,
|
||||
'background:#000000;color:#FB8C00;',
|
||||
'color:#000000;'
|
||||
);
|
||||
break;
|
||||
case 'note':
|
||||
console.log(
|
||||
`%c Note: %c ${logPackage.message}`,
|
||||
'background:#42A5F5;color:#ffffff',
|
||||
'color:#42A5F5;'
|
||||
);
|
||||
break;
|
||||
default:
|
||||
console.log(`unknown logType for "${logPackage.message}"`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
2
ts_destination_devtools/plugins.ts
Normal file
2
ts_destination_devtools/plugins.ts
Normal file
@ -0,0 +1,2 @@
|
||||
import * as smartlogInterfaces from '../dist_ts_interfaces/index.js';
|
||||
export { smartlogInterfaces };
|
23
ts_destination_file/index.ts
Normal file
23
ts_destination_file/index.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import * as plugins from './smartfile-destination-file.plugins.js';
|
||||
|
||||
export class SmartlogDestinationFile implements plugins.smartlogInterfaces.ILogDestination {
|
||||
public fileWriteStream: plugins.fs.WriteStream;
|
||||
|
||||
public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
this.fileWriteStream.write(`${new plugins.smarttime.ExtendedDate(Date.now()).toISOString()}: ${logPackageArg.message} \n`);
|
||||
}
|
||||
|
||||
constructor(filePathArg: string) {
|
||||
const extendedDate = new plugins.smarttime.ExtendedDate(Date.now());
|
||||
if (!plugins.path.isAbsolute(filePathArg)) {
|
||||
throw new Error(`filePath needs to be absolute but is not: "${filePathArg}"`);
|
||||
}
|
||||
plugins.smartfile.fs.ensureFileSync(filePathArg, `# Smartlogfile. Created at ${extendedDate.toISOString()}\n`);
|
||||
this.fileWriteStream = plugins.fs.createWriteStream(
|
||||
filePathArg,
|
||||
{
|
||||
flags: 'a+',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
19
ts_destination_file/smartfile-destination-file.plugins.ts
Normal file
19
ts_destination_file/smartfile-destination-file.plugins.ts
Normal file
@ -0,0 +1,19 @@
|
||||
// node native scope
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
fs,
|
||||
path
|
||||
};
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartlogInterfaces from '../dist_ts_interfaces/index.js';
|
||||
import * as smarttime from '@push.rocks/smarttime';
|
||||
|
||||
export {
|
||||
smartfile,
|
||||
smartlogInterfaces,
|
||||
smarttime
|
||||
};
|
8
ts_destination_local/00_commitinfo_data.ts
Normal file
8
ts_destination_local/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog-destination-local',
|
||||
version: '9.0.2',
|
||||
description: 'a smartlog destination targeting the local console'
|
||||
}
|
135
ts_destination_local/classes.destinationlocal.ts
Normal file
135
ts_destination_local/classes.destinationlocal.ts
Normal file
@ -0,0 +1,135 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import type { ILogDestination, ILogPackage, TLogLevel } from '../dist_ts_interfaces/index.js';
|
||||
|
||||
// other beautylog classes
|
||||
import { type TColorName } from '@push.rocks/consolecolor';
|
||||
|
||||
export class DestinationLocal implements ILogDestination {
|
||||
/**
|
||||
* handles a log according to the smartlog standard
|
||||
* @param logPackage
|
||||
*/
|
||||
public async handleLog(logPackage: ILogPackage) {
|
||||
this.logToConsole(logPackage);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new empty line
|
||||
* @param linesArg
|
||||
* @returns void
|
||||
*/
|
||||
public newLine(linesArg: number = 1) {
|
||||
for (let i = 0; i < linesArg; i++) {
|
||||
console.log('\n');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* logs a reduced log that only logs changes of consequential log messages
|
||||
*/
|
||||
public logReduced(logTextArg: string, repeatEveryTimesArg: number = 0) {
|
||||
if (
|
||||
logTextArg === this.previousMessage &&
|
||||
(repeatEveryTimesArg === 0 || this.sameMessageCounter !== repeatEveryTimesArg)
|
||||
) {
|
||||
this.sameMessageCounter++;
|
||||
} else {
|
||||
this.sameMessageCounter = 0;
|
||||
this.previousMessage = logTextArg;
|
||||
this.logToConsole({
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level: 'info',
|
||||
context: {
|
||||
company: 'undefined',
|
||||
companyunit: 'undefined',
|
||||
containerName: 'undefined',
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'undefined',
|
||||
},
|
||||
message: logTextArg,
|
||||
correlation: {
|
||||
id: 'none',
|
||||
type: 'none',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
private previousMessage: string = '';
|
||||
private sameMessageCounter: number = 0;
|
||||
|
||||
// default logging
|
||||
private logToConsole(logPackageArg: ILogPackage) {
|
||||
let logString: string;
|
||||
try {
|
||||
logString =
|
||||
this.localBl[logPackageArg.level].prefix +
|
||||
plugins.consolecolor.coloredString(
|
||||
logPackageArg.message,
|
||||
this.localBl[logPackageArg.level].textColor
|
||||
);
|
||||
console.log(logString);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log(
|
||||
this.localBl.errorPrefix + 'You seem to have tried logging something strange' + error
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private localBl: {
|
||||
[key: string]: {
|
||||
prefix: string;
|
||||
textColor: TColorName;
|
||||
};
|
||||
} = {
|
||||
silly: {
|
||||
prefix: plugins.consolecolor.coloredString(' silly ', 'white', 'blue') + ' ',
|
||||
textColor: 'blue',
|
||||
},
|
||||
error: {
|
||||
prefix:
|
||||
plugins.consolecolor.coloredString(' ', 'red', 'red') +
|
||||
plugins.consolecolor.coloredString(' ERROR! ', 'red', 'black') +
|
||||
' ',
|
||||
textColor: 'red',
|
||||
},
|
||||
info: {
|
||||
prefix:
|
||||
plugins.consolecolor.coloredString(' ', 'blue', 'blue') +
|
||||
plugins.consolecolor.coloredString(' info: ', 'blue', 'black') +
|
||||
' ',
|
||||
textColor: 'white',
|
||||
},
|
||||
note: {
|
||||
prefix:
|
||||
plugins.consolecolor.coloredString(' ', 'pink', 'pink') +
|
||||
plugins.consolecolor.coloredString(' note -> ', 'pink', 'black') +
|
||||
' ',
|
||||
textColor: 'pink',
|
||||
},
|
||||
ok: {
|
||||
prefix:
|
||||
plugins.consolecolor.coloredString(' ', 'green', 'green') +
|
||||
plugins.consolecolor.coloredString(' ok ', 'green', 'black') +
|
||||
' ',
|
||||
textColor: 'green',
|
||||
},
|
||||
success: {
|
||||
prefix:
|
||||
plugins.consolecolor.coloredString(' ', 'green', 'green') +
|
||||
plugins.consolecolor.coloredString(' SUCCESS! ', 'green', 'black') +
|
||||
' ',
|
||||
textColor: 'green',
|
||||
},
|
||||
warn: {
|
||||
prefix:
|
||||
plugins.consolecolor.coloredString(' ', 'orange', 'orange') +
|
||||
plugins.consolecolor.coloredString(' WARN -> ', 'orange', 'black') +
|
||||
' ',
|
||||
textColor: 'orange',
|
||||
},
|
||||
};
|
||||
}
|
2
ts_destination_local/index.ts
Normal file
2
ts_destination_local/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
// export classes
|
||||
export { DestinationLocal } from './classes.destinationlocal.js';
|
5
ts_destination_local/plugins.ts
Normal file
5
ts_destination_local/plugins.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import * as consolecolor from '@push.rocks/consolecolor';
|
||||
import * as smartlogInterfaces from '../dist_ts_interfaces/index.js';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { consolecolor, smartlogInterfaces, smartpromise };
|
8
ts_destination_receiver/00_commitinfo_data.ts
Normal file
8
ts_destination_receiver/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog-destination-receiver',
|
||||
version: '2.0.6',
|
||||
description: 'A package providing a destination handler for smartlog logging packages'
|
||||
}
|
35
ts_destination_receiver/index.ts
Normal file
35
ts_destination_receiver/index.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import * as plugins from './smartlog-destination-receiver.plugins.js';
|
||||
import {
|
||||
type ILogDestination,
|
||||
type ILogPackageAuthenticated,
|
||||
type ILogPackage,
|
||||
} from '../dist_ts_interfaces/index.js';
|
||||
|
||||
export interface ISmartlogDestinationReceiverConstructorOptions {
|
||||
passphrase: string;
|
||||
receiverEndpoint: string;
|
||||
}
|
||||
|
||||
export class SmartlogDestinationReceiver implements ILogDestination {
|
||||
private options: ISmartlogDestinationReceiverConstructorOptions;
|
||||
private webrequest = new plugins.webrequest.WebRequest();
|
||||
|
||||
constructor(optionsArg: ISmartlogDestinationReceiverConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
private errorCounter = 0;
|
||||
public async handleLog(logPackageArg: ILogPackage) {
|
||||
const response = await this.webrequest.postJson(this.options.receiverEndpoint, {
|
||||
auth: plugins.smarthash.sha256FromStringSync(this.options.passphrase),
|
||||
logPackage: logPackageArg,
|
||||
}).catch(err => {
|
||||
if (this.errorCounter % 100 === 0) {
|
||||
console.error(`There seems to be an error with logging.`);
|
||||
console.error(`Accumulated ${this.errorCounter} errors so far`)
|
||||
}
|
||||
this.errorCounter++;
|
||||
});
|
||||
return response.body;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
import * as smartlogInterfaces from '../dist_ts_interfaces/index.js';
|
||||
import * as webrequest from '@push.rocks/webrequest';
|
||||
|
||||
export { smarthash, smartlogInterfaces, webrequest };
|
8
ts_interfaces/00_commitinfo_data.ts
Normal file
8
ts_interfaces/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog-interfaces',
|
||||
version: '3.0.2',
|
||||
description: 'Defines interfaces for the smartlog ecosystem.'
|
||||
}
|
126
ts_interfaces/index.ts
Normal file
126
ts_interfaces/index.ts
Normal file
@ -0,0 +1,126 @@
|
||||
import * as plugins from './smartlog-interfaces.plugins.js';
|
||||
|
||||
import * as requestInterfaces from './smartlog-interfaces.requests.js';
|
||||
|
||||
export { requestInterfaces as request };
|
||||
|
||||
/**
|
||||
* the different available log types
|
||||
*/
|
||||
export type TLogType =
|
||||
| 'log'
|
||||
| 'increment'
|
||||
| 'gauge'
|
||||
| 'error'
|
||||
| 'success'
|
||||
| 'value'
|
||||
| 'finance'
|
||||
| 'compliance';
|
||||
|
||||
/**
|
||||
* the available log levels
|
||||
*/
|
||||
export type TLogLevel =
|
||||
| 'silly'
|
||||
| 'info'
|
||||
| 'debug'
|
||||
| 'note'
|
||||
| 'ok'
|
||||
| 'success'
|
||||
| 'warn'
|
||||
| 'error'
|
||||
| 'lifecycle';
|
||||
|
||||
/**
|
||||
* the available environments
|
||||
*/
|
||||
export type TEnvironment = 'local' | 'test' | 'staging' | 'production';
|
||||
|
||||
/**
|
||||
* the available runtimes
|
||||
*/
|
||||
export type TRuntime = 'node' | 'chrome' | 'rust' | 'deno' | 'cloudflare_workers';
|
||||
|
||||
/**
|
||||
* the log context e.g. what app in what version on what server
|
||||
*/
|
||||
export interface ILogContext {
|
||||
commitinfo?: plugins.tsclass.code.ICommitInfo;
|
||||
company?: string;
|
||||
companyunit?: string;
|
||||
containerName?: string;
|
||||
environment?: TEnvironment;
|
||||
runtime?: TRuntime;
|
||||
zone?: string;
|
||||
}
|
||||
|
||||
export interface ILogCorrelation {
|
||||
/**
|
||||
* a unique id for this log
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* the type of this log
|
||||
*/
|
||||
type: 'none' | 'service' | 'build' | 'infrastructure' | 'cdn';
|
||||
/**
|
||||
* the instance on which the log is created
|
||||
* use it for pinning logs to a certain instance in a cluster
|
||||
*/
|
||||
instance?: string;
|
||||
/**
|
||||
* a series of logs
|
||||
*/
|
||||
group?: string;
|
||||
/**
|
||||
* a log that belongs to a transaction. E.g. a Payment or a request traveling through multiple backend instances
|
||||
*/
|
||||
transaction?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* the main logpackage
|
||||
*/
|
||||
export interface ILogPackage<T = unknown> {
|
||||
/**
|
||||
* a unix timestamp in milliseconds
|
||||
*/
|
||||
timestamp: number;
|
||||
type: TLogType;
|
||||
context: ILogContext;
|
||||
level: TLogLevel;
|
||||
/**
|
||||
* allows grouping of log messages
|
||||
*/
|
||||
correlation: ILogCorrelation;
|
||||
/**
|
||||
* the message to log
|
||||
*/
|
||||
message: string;
|
||||
data?: T;
|
||||
}
|
||||
|
||||
export interface ILogPackageDataRequest {
|
||||
requestCorrelationId: string;
|
||||
url: string;
|
||||
pathname: string;
|
||||
method: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface ILogPackageAuthenticated {
|
||||
auth: string;
|
||||
logPackage: ILogPackage;
|
||||
}
|
||||
|
||||
export interface ILogPackageArrayAuthenticated {
|
||||
auth: string;
|
||||
logPackages: ILogPackage[];
|
||||
}
|
||||
|
||||
/**
|
||||
* a destination interface for extending smartlog modules
|
||||
*/
|
||||
export interface ILogDestination {
|
||||
handleLog: (logPackage: ILogPackage) => Promise<void>;
|
||||
}
|
10
ts_interfaces/smartlog-interfaces.plugins.ts
Normal file
10
ts_interfaces/smartlog-interfaces.plugins.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
|
||||
|
||||
export { typedrequestInterfaces };
|
||||
|
||||
// tsclass scope
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export {
|
||||
tsclass
|
||||
}
|
9
ts_interfaces/smartlog-interfaces.requests.ts
Normal file
9
ts_interfaces/smartlog-interfaces.requests.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { type ILogPackageAuthenticated } from './index.js';
|
||||
|
||||
export interface IRequest_SmartlogDestinationReceiver_Any_PostLogPackages {
|
||||
method: 'postLogPackages';
|
||||
request: {
|
||||
logPackages: ILogPackageAuthenticated[];
|
||||
};
|
||||
response: {};
|
||||
}
|
8
ts_receiver/00_commitinfo_data.ts
Normal file
8
ts_receiver/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog-receiver',
|
||||
version: '2.0.0',
|
||||
description: 'a receiver for smartlog-destination-receiver'
|
||||
}
|
1
ts_receiver/index.ts
Normal file
1
ts_receiver/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './sl.classes.smartlogreceiver.js';
|
73
ts_receiver/sl.classes.smartlogreceiver.ts
Normal file
73
ts_receiver/sl.classes.smartlogreceiver.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import * as plugins from './sl.receiver.plugins.js';
|
||||
|
||||
import type {
|
||||
ILogPackage,
|
||||
ILogPackageAuthenticated,
|
||||
ILogDestination,
|
||||
} from '../dist_ts_interfaces/index.js';
|
||||
|
||||
export type TValidatorFunction = (logPackage: ILogPackage) => Promise<boolean>;
|
||||
|
||||
export interface ISmartlogReceiverOptions {
|
||||
smartlogInstance: plugins.smartlog.Smartlog;
|
||||
passphrase: string;
|
||||
validatorFunction: TValidatorFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* a class that receives smartlog packages
|
||||
*/
|
||||
export class SmartlogReceiver {
|
||||
public passphrase: string;
|
||||
public validatorFunction: TValidatorFunction;
|
||||
public smartlogInstance: plugins.smartlog.Smartlog;
|
||||
|
||||
constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) {
|
||||
this.passphrase = smartlogReceiverOptions.passphrase;
|
||||
this.validatorFunction =
|
||||
smartlogReceiverOptions.validatorFunction ||
|
||||
(async (logpackageArg) => {
|
||||
return true;
|
||||
});
|
||||
this.smartlogInstance = smartlogReceiverOptions.smartlogInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* handles a authenticated log
|
||||
*/
|
||||
public async handleAuthenticatedLog(authenticatedLogPackageArg: ILogPackageAuthenticated) {
|
||||
const authString = authenticatedLogPackageArg.auth;
|
||||
const logPackage = authenticatedLogPackageArg.logPackage;
|
||||
|
||||
if (
|
||||
authString === plugins.smarthash.sha256FromStringSync(this.passphrase) &&
|
||||
(await this.validatorFunction(logPackage))
|
||||
) {
|
||||
// Message authenticated lets clean up.
|
||||
logPackage.correlation ? null : (logPackage.correlation = { id: '123', type: 'none' });
|
||||
logPackage.correlation.id ? null : (logPackage.correlation.id = '123');
|
||||
logPackage.correlation.type ? null : (logPackage.correlation.type = 'none');
|
||||
|
||||
this.smartlogInstance.handleLog(logPackage);
|
||||
return { status: 'ok' };
|
||||
} else {
|
||||
this.smartlogInstance.log('error', 'Message rejected because of bad passphrase');
|
||||
return { status: 'error' };
|
||||
// console.log(plugins.smarthash.sha256FromStringSync(this.passphrase));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handles an array of authenticated logs
|
||||
* @param authenticatedLogsPackageArrayArg
|
||||
*/
|
||||
public async handleManyAuthenticatedLogs(
|
||||
authenticatedLogsPackageArrayArg: ILogPackageAuthenticated[]
|
||||
) {
|
||||
const promiseArray: Array<Promise<any>> = [];
|
||||
for (const logPackage of authenticatedLogsPackageArrayArg) {
|
||||
promiseArray.push(this.handleAuthenticatedLog(logPackage));
|
||||
}
|
||||
await Promise.all(promiseArray);
|
||||
}
|
||||
}
|
4
ts_receiver/sl.receiver.plugins.ts
Normal file
4
ts_receiver/sl.receiver.plugins.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
import * as smartlog from '../dist_ts/index.js';
|
||||
|
||||
export { smartlog, smarthash };
|
40
ts_source_ora/index.ts
Normal file
40
ts_source_ora/index.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as plugins from './smartlog-source-ora.plugins.js';
|
||||
|
||||
export class SmartlogSourceOra {
|
||||
public oraInstance = plugins.ora('loading');
|
||||
public started = false;
|
||||
|
||||
constructor() {}
|
||||
|
||||
public text(textArg: string) {
|
||||
this.oraInstance.text = textArg;
|
||||
if (!this.started) {
|
||||
this.started = true;
|
||||
this.oraInstance.start();
|
||||
}
|
||||
}
|
||||
|
||||
public stop() {
|
||||
this.oraInstance.stop();
|
||||
}
|
||||
|
||||
public finishSuccess(textArg?: string) {
|
||||
this.oraInstance.succeed(textArg);
|
||||
this.started = false;
|
||||
}
|
||||
|
||||
public finishFail(textArg?: string) {
|
||||
this.oraInstance.fail(textArg);
|
||||
this.started = false;
|
||||
}
|
||||
|
||||
public successAndNext(textArg: string) {
|
||||
this.finishSuccess();
|
||||
this.text(textArg);
|
||||
}
|
||||
|
||||
public failAndNext(textArg: string) {
|
||||
this.finishFail();
|
||||
this.text(textArg);
|
||||
}
|
||||
}
|
9
ts_source_ora/smartlog-source-ora.plugins.ts
Normal file
9
ts_source_ora/smartlog-source-ora.plugins.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// pushrocks scope
|
||||
import * as smartlogInterfaces from '../dist_ts_interfaces/index.js';
|
||||
|
||||
export { smartlogInterfaces };
|
||||
|
||||
// third party scope
|
||||
import ora from 'ora';
|
||||
|
||||
export { ora };
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user