Package Exports
- @inctasoft/simple-log-ts
- @inctasoft/simple-log-ts/dist/src/log.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@inctasoft/simple-log-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
simple-log-ts
npm install @inctasoft/simple-log-ts
Exposes a Log
class with debug
, info
, warn
, error
and crit
methods.
- Logs are in JSON format, useful for parsing from log ingesting services
Error
,Map
Set
objects are trnsformed into JSON and also printed
Examples
- Empty config
import { Log } from "@inctasoft/simple-log-ts";
const log = new Log();
log.error("oops something hapened, new Error('some err msg'));
results in:
{"timestamp":"2023-10-11T21:50:47.405Z","level":"ERROR","message":"oops something hapened","correlation":"undefined","[Error]":{"stack":"Error: some err msg\n at Object......","message":"some err msg"}}```
- Printing complex objects, and providing
correlation_id
import { Log } from "@inctasoft/simple-log-ts";
process.env.LOGLEVEL = 'DEBUG' // un-silence debug method
const log = new Log({ correlation_id: 'some_guid' });
log.debug({
a: 1, b: 'xyz', my_set: new Set(['foo', 'bar']), nested: {
my_arr: [
'elem1',
new Map([['mapKey', {
prop1: 1,
prop2: new Date()
}]])]
}
});
results in:
{"timestamp":"2023-10-12T00:14:44.139Z","level":"DEBUG","message":{"a":1,"b":"xyz","my_set":["foo","bar"],"nested":{"my_arr":["elem1",{"mapKey":{"prop1":1,"prop2":"2023-10-12T00:14:44.139Z"}}]}},"correlation":"some_guid"}
- If you are interested in which transformed objects were of
Map
orSet
types, provideprintMapSetTypes: true
- If you are not into using correlation_id, provide
printCorrelation: false
import { Log } from "@inctasoft/simple-log-ts";
const log = new Log({ printMapSetTypes: true, printCorrelation: false});
log.warn({
a: 1, b: 'xyz', my_set: new Set(['foo', 'bar']), nested: {
my_arr: [
'elem1',
new Map([['mapKey', {
prop1: 1,
prop2: new Date()
}]])]
}
});
log statement:
{"timestamp":"2023-10-11T22:04:00.503Z","level":"WARN","message":{"a":1,"b":"xyz","my_set":{"[Set]":["foo","bar"]},"nested":{"my_arr":["elem1",{"[Map]":{"mapKey":{"prop1":1,"prop2":"2023-10-11T22:04:00.503Z"}}}]}}}
Log levels
process.env.LOGLEVEL | active methods | notes |
---|---|---|
DEBUG |
debug ,info ,warn ,error ,crit |
|
INFO |
info ,warn ,error ,crit |
|
WARN |
warn ,error ,crit |
default, if no LOGLEVEL is present |
ERROR |
error ,crit |
Both crit and error use console.error and accept optional second Error argument |
SILENT (or any other value) |
crit |
Lets you silence all logs, if not using crit method(as it is always active, no matter of LOGLEVEL value) |
CICD
- PRs to
dev
,main
,release/**
,hotfix/**
will trigger github workflow to Build, Test, Sonarcloud scan - On push to
main
,release/**
orhotfix/**
, commits are pulled back indev
branch - On push to
main
:- package version is bumped depending on commit messages
- see https://github.com/phips28/gh-action-bump-version#workflow on commit messages
- (version bump commit will be automerged in
dev
from 2.)
- new tag is being created with the new version
- npm package with the new version is pushed to https://registry.npmjs.org/
- npm package with the new version is pushed to https://npm.pkg.github.com/
- package version is bumped depending on commit messages
- pre-commit hooks are running tests and linting commit messages. Using
git cz
is encouraged - Github releases from tags are manually created for editing the release notes
This repo as template
- Upon creating a repository from the template the Gthub Actions pipeline will fail for the
sonarcloud
step - You would want to first
- One-time execute
npm run prepare
to install git hooks - remove other files, change contents of
package.json
, etc. - make sure these secrets exists, have access to your repo and are valid:
PAT_TOKEN_GHA_AUTH
the token of the account to setup git for automatic version bumps and mergebacks in dev. Needs arepo
scopeSONAR_TOKEN
- sonar cloud token. You will need a https://sonarcloud.io/ account and a corresponding projectNPM_TOKEN
- NPM token (classic). You will need a https://www.npmjs.com/ account
- One-time execute