-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
7,251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
|
||
# Change these settings to your own preference | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
# We recommend you to keep these unchanged | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
# Markdown specific settings | ||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
VERSION_BUMP: | ||
description: 'The version bump' | ||
type: choice | ||
options: | ||
- major | ||
- minor | ||
- patch | ||
default: minor | ||
required: true | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
concurrency: "1" | ||
environment: release | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.RELEASE_GITHUB_TOKEN }} | ||
|
||
- name: Setup Node.js version | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Configure git | ||
run: | | ||
git config user.name "Uphold" | ||
git config user.email "[email protected]" | ||
- name: Generate release | ||
env: | ||
NPM_TOKEN: ${{ secrets.RELEASE_NPM_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} | ||
run: | | ||
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc | ||
npm run release -- --increment ${{ github.event.inputs.VERSION_BUMP }} -V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js version | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run lint | ||
run: npm run lint | ||
|
||
- name: Run tests | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.dump | ||
*.dump.bz2.gpg | ||
coverage | ||
node_modules | ||
npm-debug.log* | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"git": { | ||
"changelog": "echo \"## Changelog\\n\\n$(npx @uphold/github-changelog-generator -f unreleased | tail -n +4 -f)\"", | ||
"requireCleanWorkingDir": false, | ||
"commitMessage": "Release `v${version}`", | ||
"requireBranch": "master", | ||
"requireCommits": true, | ||
"tagName": "v${version}" | ||
}, | ||
"github": { | ||
"release": true, | ||
"releaseName": "v${version}" | ||
}, | ||
"hooks": { | ||
"after:bump": [ | ||
"touch CHANGELOG.md", | ||
"echo \"$(npx @uphold/github-changelog-generator -f v${version})\n$(tail -n +2 CHANGELOG.md)\" > CHANGELOG.md", | ||
"git add CHANGELOG.md --all" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Uphold | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,108 @@ | ||
# debino | ||
|
||
[![Tests](https://github.com/uphold/debino/actions/workflows/tests.yaml/badge.svg)](https://github.com/uphold/debino/actions/workflows/tests.yaml) | ||
[![Release](https://github.com/uphold/debino/actions/workflows/release.yaml/badge.svg)](https://github.com/uphold/debino/actions/workflows/release.yaml) | ||
|
||
A logging library that combines the simplicity and convenience of [debug](https://github.com/debug-js/debug) with the power of [pino](https://github.com/pinojs/pino). | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @uphold/debino pino | ||
``` | ||
|
||
## Usage | ||
|
||
By default, similarly to `debug`'s behavior, loggers do not output any content. Each logger output can be selectively activated by using the `DEBUG` environment variable. Pattern matching is based on the logger's name and it can optionally contain colons (`:`) to create (sub)-components properties on the logger instance. | ||
|
||
A logger named `foo:bar:biz` creates a `pino` child logger with `name` equal to `foo`, property `component` equal to `bar` and `subcomponent` equal to `biz`. | ||
|
||
Considering the following example: | ||
|
||
```js | ||
// example.js | ||
import debino from '@uphold/debino'; | ||
|
||
const child1 = debino('foo'); | ||
const child2 = debino('foo:bar'); | ||
|
||
child1.debug('net'); | ||
child2.debug('qux'); | ||
``` | ||
|
||
*Example output with `DEBUG=foo*`*: | ||
|
||
```bash | ||
DEBUG=foo* node example.js | ||
|
||
{"level":20,"time":1734717092221,"pid":99831,"hostname":"Andr-Cruz-0688L","name":"foo","msg":"net"} | ||
{"level":20,"time":1734717092221,"pid":99831,"hostname":"Andr-Cruz-0688L","name":"foo","component":"bar","msg":"qux"} | ||
``` | ||
|
||
*Example output with `DEBUG=foo:bar`*: | ||
|
||
```bash | ||
DEBUG=foo:bar node example.js | ||
|
||
{"level":20,"time":1734717270874,"pid":1035,"hostname":"Andr-Cruz-0688L","name":"foo","component":"bar","msg":"qux"} | ||
``` | ||
|
||
The `prefix` and `suffix` for each component is also customizable: | ||
|
||
```js | ||
const child = debino('foo', { suffix: 'module' }); | ||
``` | ||
|
||
When creating a child logger, you may also pass any options accepted by `pino.child()` method: | ||
|
||
```js | ||
const child = debino('foo', { redact: ['foo']}); | ||
``` | ||
|
||
### Log level | ||
|
||
The `level` pino option is respected if the logger output is active. | ||
|
||
```js | ||
const logger = debino('root')('foo', { level: 'info' }); | ||
``` | ||
|
||
You may also set the log level via the `LOG_LEVEL` environment variable. However, the `level` option will always take precedence over it. | ||
|
||
### Root logger | ||
|
||
Every call to `debino` creates a child logger based on a root logger. The default root logger is an instance returned by `pino()`, without any options. You may set your own root logger by calling `setRootLogger()`: | ||
|
||
```js | ||
import pino from 'pino'; | ||
import debino, { setRootLogger } from '@uphold/debino'; | ||
|
||
// Call this as soon as possible in your application. | ||
setRootLogger(pino({ redact: ['foo'] })); | ||
|
||
const logger = debino('foo'); | ||
``` | ||
|
||
## License | ||
|
||
[MIT](./LICENSE) | ||
|
||
## Contributing | ||
|
||
### Development | ||
|
||
Install dependencies: | ||
|
||
```bash | ||
npm i | ||
``` | ||
|
||
Run tests: | ||
|
||
```bash | ||
npm run test | ||
``` | ||
|
||
### Cutting a release | ||
|
||
The release process is automated via the [release](https://github.com/uphold/debino/actions/workflows/release.yaml) GitHub workflow. Run it by clicking the "Run workflow" button. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; | ||
import globals from 'globals'; | ||
import pluginJs from '@eslint/js'; | ||
import sortDestructureKeys from 'eslint-plugin-sort-destructure-keys'; | ||
import sortImportsRequires from 'eslint-plugin-sort-imports-requires'; | ||
import sortKeysFix from 'eslint-plugin-sort-keys-fix'; | ||
|
||
export default [ | ||
{ languageOptions: { globals: globals.node } }, | ||
pluginJs.configs.recommended, | ||
eslintPluginPrettierRecommended, | ||
{ | ||
plugins: { | ||
'sort-destructure-keys': sortDestructureKeys, | ||
'sort-imports-requires': sortImportsRequires, | ||
'sort-keys-fix': sortKeysFix | ||
}, | ||
rules: { | ||
'prettier/prettier': [ | ||
'error', | ||
{ | ||
arrowParens: 'avoid', | ||
printWidth: 120, | ||
singleQuote: true, | ||
trailingComma: 'none' | ||
} | ||
], | ||
'sort-destructure-keys/sort-destructure-keys': 'error', | ||
'sort-imports-requires/sort-imports': [ | ||
'error', | ||
{ | ||
unsafeAutofix: true, | ||
useOldSingleMemberSyntax: true | ||
} | ||
], | ||
'sort-imports-requires/sort-requires': [ | ||
'error', | ||
{ | ||
unsafeAutofix: true, | ||
useAliases: false, | ||
useOldSingleMemberSyntax: true | ||
} | ||
], | ||
'sort-keys-fix/sort-keys-fix': ['error', 'asc', { natural: true }] | ||
} | ||
} | ||
]; |
Oops, something went wrong.