Skip to content

Commit a27442c

Browse files
authored
Merge pull request #14 from MatrixAI/feature-structured-logging
Structured JSON Logging
2 parents fc0f586 + c46a8ed commit a27442c

23 files changed

+1931
-2526
lines changed

.gitlab-ci.yml

+56-55
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,35 @@ workflow:
55
when: never
66
- when: always
77

8-
default:
9-
interruptible: true
10-
118
variables:
9+
GIT_SUBMODULE_STRATEGY: recursive
1210
GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}"
1311
GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git"
14-
GIT_SUBMODULE_STRATEGY: recursive
1512
# Cache .npm
1613
NPM_CONFIG_CACHE: "${CI_PROJECT_DIR}/tmp/npm"
1714
# Prefer offline node module installation
1815
NPM_CONFIG_PREFER_OFFLINE: "true"
1916
# Homebrew cache only used by macos runner
2017
HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew"
2118

19+
default:
20+
interruptible: true
21+
before_script:
22+
# Replace this in windows runners that use powershell
23+
# with `mkdir -Force "$CI_PROJECT_DIR/tmp"`
24+
- mkdir -p "$CI_PROJECT_DIR/tmp"
25+
2226
# Cached directories shared between jobs & pipelines per-branch per-runner
2327
cache:
2428
key: $CI_COMMIT_REF_SLUG
29+
# Preserve cache even if job fails
30+
when: 'always'
2531
paths:
2632
- ./tmp/npm/
2733
# Homebrew cache is only used by the macos runner
2834
- ./tmp/Homebrew
35+
# Chocolatey cache is only used by the windows runner
36+
- ./tmp/chocolatey/
2937
# `jest` cache is configured in jest.config.js
3038
- ./tmp/jest/
3139

@@ -42,9 +50,10 @@ check:lint:
4250
needs: []
4351
script:
4452
- >
45-
nix-shell --run '
46-
npm run lint;
47-
'
53+
nix-shell --arg ci true --run '
54+
npm run lint;
55+
npm run lint-shell;
56+
'
4857
rules:
4958
# Runs on feature and staging commits and ignores version commits
5059
- if: $CI_COMMIT_BRANCH =~ /^(?:feature.*|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -59,10 +68,9 @@ check:test:
5968
needs: []
6069
script:
6170
- >
62-
nix-shell --run '
63-
npm run build --verbose;
64-
npm test -- --ci --coverage;
65-
'
71+
nix-shell --arg ci true --run '
72+
npm test -- --ci --coverage;
73+
'
6674
artifacts:
6775
when: always
6876
reports:
@@ -87,20 +95,20 @@ build:merge:
8795
# Required for `gh pr create`
8896
- git remote add upstream "$GH_PROJECT_URL"
8997
- >
90-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
91-
gh pr create \
92-
--head staging \
93-
--base master \
94-
--title "ci: merge staging to master" \
95-
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
96-
--assignee "@me" \
97-
--no-maintainer-edit \
98-
--repo "$GH_PROJECT_PATH" || true;
99-
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
100-
| gh pr comment staging \
101-
--body-file - \
102-
--repo "$GH_PROJECT_PATH";
103-
'
98+
nix-shell --arg ci true --run '
99+
gh pr create \
100+
--head staging \
101+
--base master \
102+
--title "ci: merge staging to master" \
103+
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
104+
--assignee "@me" \
105+
--no-maintainer-edit \
106+
--repo "$GH_PROJECT_PATH" || true;
107+
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
108+
| gh pr comment staging \
109+
--body-file - \
110+
--repo "$GH_PROJECT_PATH";
111+
'
104112
rules:
105113
# Runs on staging commits and ignores version commits
106114
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -112,10 +120,10 @@ build:linux:
112120
needs: []
113121
script:
114122
- >
115-
nix-shell --run '
116-
npm run build --verbose;
117-
npm test -- --ci --coverage;
118-
'
123+
nix-shell --arg ci true --run '
124+
npm run build --verbose;
125+
npm test -- --ci --coverage;
126+
'
119127
artifacts:
120128
when: always
121129
reports:
@@ -140,10 +148,10 @@ build:windows:
140148
tags:
141149
- windows
142150
before_script:
143-
- choco install nodejs --version=16.14.2 -y
144-
- refreshenv
151+
- mkdir -Force "$CI_PROJECT_DIR/tmp"
145152
script:
146-
- npm config set msvs_version 2019
153+
- .\scripts\choco-install.ps1
154+
- refreshenv
147155
- npm install --ignore-scripts
148156
- $env:Path = "$(npm bin);" + $env:Path
149157
- npm run build --verbose
@@ -165,15 +173,10 @@ build:macos:
165173
tags:
166174
- shared-macos-amd64
167175
image: macos-11-xcode-12
168-
variables:
169-
HOMEBREW_NO_INSTALL_UPGRADE: "true"
170-
HOMEBREW_NO_INSTALL_CLEANUP: "true"
171-
before_script:
176+
script:
172177
- eval "$(brew shellenv)"
173-
- brew install node@16
174-
- brew link --overwrite node@16
178+
- ./scripts/brew-install.sh
175179
- hash -r
176-
script:
177180
- npm install --ignore-scripts
178181
- export PATH="$(npm bin):$PATH"
179182
- npm run build --verbose
@@ -197,14 +200,13 @@ build:prerelease:
197200
- build:macos
198201
# Don't interrupt publishing job
199202
interruptible: false
200-
before_script:
201-
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
202203
script:
204+
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
203205
- echo 'Publishing library prerelease'
204206
- >
205-
nix-shell --run '
206-
npm publish --tag prerelease --access public;
207-
'
207+
nix-shell --arg ci true --run '
208+
npm publish --tag prerelease --access public;
209+
'
208210
after_script:
209211
- rm -f ./.npmrc
210212
rules:
@@ -234,12 +236,12 @@ integration:merge:
234236
GIT_DEPTH: 0
235237
script:
236238
- >
237-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
238-
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
239-
| gh pr comment staging \
240-
--body-file - \
241-
--repo "$GH_PROJECT_PATH";
242-
'
239+
nix-shell --arg ci true --run '
240+
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
241+
| gh pr comment staging \
242+
--body-file - \
243+
--repo "$GH_PROJECT_PATH";
244+
'
243245
- git remote add upstream "$GH_PROJECT_URL"
244246
- git checkout origin/master
245247
# Merge up to the current commit (not the latest commit)
@@ -260,14 +262,13 @@ release:distribution:
260262
- integration:merge
261263
# Don't interrupt publishing job
262264
interruptible: false
263-
before_script:
264-
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
265265
script:
266+
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
266267
- echo 'Publishing library'
267268
- >
268-
nix-shell --run '
269-
npm publish --access public;
270-
'
269+
nix-shell --arg ci true --run '
270+
npm publish --access public;
271+
'
271272
after_script:
272273
- rm -f ./.npmrc
273274
rules:

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ See the docs at: https://matrixai.github.io/js-logger/
4040

4141
### Publishing
4242

43+
Publishing is handled automatically by the staging pipeline.
44+
45+
Prerelease:
46+
47+
```sh
48+
# npm login
49+
npm version prepatch --preid alpha # premajor/preminor/prepatch
50+
git push --follow-tags
51+
```
52+
53+
Release:
54+
55+
```sh
56+
# npm login
57+
npm version patch # major/minor/patch
58+
git push --follow-tags
59+
```
60+
61+
Manually:
62+
4363
```sh
4464
# npm login
4565
npm version patch # major/minor/patch

docs/assets/search.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/classes/default.html

+5-1
Large diffs are not rendered by default.

docs/index.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ <h3>Docs Generation</h3>
2929
<a href="#publishing" id="publishing" style="color: inherit; text-decoration: none;">
3030
<h3>Publishing</h3>
3131
</a>
32+
<p>Publishing is handled automatically by the staging pipeline.</p>
33+
<p>Prerelease:</p>
34+
<pre><code class="language-sh"><span class="hl-1"># npm login</span><br/><span class="hl-0">npm version prepatch --preid alpha </span><span class="hl-1"># premajor/preminor/prepatch</span><br/><span class="hl-0">git push --follow-tags</span>
35+
</code></pre>
36+
<p>Release:</p>
37+
<pre><code class="language-sh"><span class="hl-1"># npm login</span><br/><span class="hl-0">npm version patch </span><span class="hl-1"># major/minor/patch</span><br/><span class="hl-0">git push --follow-tags</span>
38+
</code></pre>
39+
<p>Manually:</p>
3240
<pre><code class="language-sh"><span class="hl-1"># npm login</span><br/><span class="hl-0">npm version patch </span><span class="hl-1"># major/minor/patch</span><br/><span class="hl-0">npm run build</span><br/><span class="hl-0">npm publish --access public</span><br/><span class="hl-0">git push</span><br/><span class="hl-0">git push --tags</span>
3341
</code></pre>
34-
</div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li><li class=" tsd-kind-namespace"><a href="modules/formatting.html">formatting</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-enum"><a href="enums/LogLevel.html" class="tsd-kind-icon">Log<wbr/>Level</a></li><li class="tsd-kind-class"><a href="classes/ConsoleErrHandler.html" class="tsd-kind-icon">Console<wbr/>Err<wbr/>Handler</a></li><li class="tsd-kind-class"><a href="classes/ConsoleOutHandler.html" class="tsd-kind-icon">Console<wbr/>Out<wbr/>Handler</a></li><li class="tsd-kind-class"><a href="classes/Handler.html" class="tsd-kind-icon">Handler</a></li><li class="tsd-kind-class"><a href="classes/StreamHandler.html" class="tsd-kind-icon">Stream<wbr/>Handler</a></li><li class="tsd-kind-class"><a href="classes/default.html" class="tsd-kind-icon">default</a></li><li class="tsd-kind-interface"><a href="interfaces/ToString.html" class="tsd-kind-icon">To<wbr/>String</a></li><li class="tsd-kind-type-alias"><a href="modules.html#LogFormatter" class="tsd-kind-icon">Log<wbr/>Formatter</a></li><li class="tsd-kind-type-alias"><a href="modules.html#LogRecord" class="tsd-kind-icon">Log<wbr/>Record</a></li><li class="tsd-kind-function"><a href="modules.html#levelToString" class="tsd-kind-icon">level<wbr/>To<wbr/>String</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html>
42+
</div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li><li class=" tsd-kind-namespace"><a href="modules/formatting.html">formatting</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-enum"><a href="enums/LogLevel.html" class="tsd-kind-icon">Log<wbr/>Level</a></li><li class="tsd-kind-class"><a href="classes/ConsoleErrHandler.html" class="tsd-kind-icon">Console<wbr/>Err<wbr/>Handler</a></li><li class="tsd-kind-class"><a href="classes/ConsoleOutHandler.html" class="tsd-kind-icon">Console<wbr/>Out<wbr/>Handler</a></li><li class="tsd-kind-class"><a href="classes/Handler.html" class="tsd-kind-icon">Handler</a></li><li class="tsd-kind-class"><a href="classes/StreamHandler.html" class="tsd-kind-icon">Stream<wbr/>Handler</a></li><li class="tsd-kind-class"><a href="classes/default.html" class="tsd-kind-icon">default</a></li><li class="tsd-kind-interface"><a href="interfaces/ToJSON.html" class="tsd-kind-icon">ToJSON</a></li><li class="tsd-kind-interface"><a href="interfaces/ToString.html" class="tsd-kind-icon">To<wbr/>String</a></li><li class="tsd-kind-type-alias"><a href="modules.html#LogData" class="tsd-kind-icon">Log<wbr/>Data</a></li><li class="tsd-kind-type-alias"><a href="modules.html#LogDataKey" class="tsd-kind-icon">Log<wbr/>Data<wbr/>Key</a></li><li class="tsd-kind-type-alias"><a href="modules.html#LogDataValue" class="tsd-kind-icon">Log<wbr/>Data<wbr/>Value</a></li><li class="tsd-kind-type-alias"><a href="modules.html#LogFormatter" class="tsd-kind-icon">Log<wbr/>Formatter</a></li><li class="tsd-kind-type-alias"><a href="modules.html#LogRecord" class="tsd-kind-icon">Log<wbr/>Record</a></li><li class="tsd-kind-variable"><a href="modules.html#hasCaptureStackTrace" class="tsd-kind-icon">has<wbr/>Capture<wbr/>Stack<wbr/>Trace</a></li><li class="tsd-kind-variable"><a href="modules.html#hasStackTraceLimit" class="tsd-kind-icon">has<wbr/>Stack<wbr/>Trace<wbr/>Limit</a></li><li class="tsd-kind-function"><a href="modules.html#evalLogData" class="tsd-kind-icon">eval<wbr/>Log<wbr/>Data</a></li><li class="tsd-kind-function"><a href="modules.html#evalLogDataValue" class="tsd-kind-icon">eval<wbr/>Log<wbr/>Data<wbr/>Value</a></li><li class="tsd-kind-function"><a href="modules.html#levelToString" class="tsd-kind-icon">level<wbr/>To<wbr/>String</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html>

0 commit comments

Comments
 (0)