Package Exports
- @inctasoft/simple-log-ts
- @inctasoft/simple-log-ts/dist/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
NOTE
- This is a very simple logger, providing support for loglevels and
correlation
string that is always logged - If you are looking for a decent logger in the context of AWS, you may want to consider using https://docs.powertools.aws.dev/lambda/typescript/latest/core/logger/
- This repo and the code in it (although working) is used to scafold a github workflows for a Node.js SDLC.
Workflow
dev
,main
,release/**
,hotfix/**
are protected branchesdev
is default 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
- new tag is being created with the newly bumped version
- package version is bumped depending on commit messages
- on push to
main
,release/**
orhotfix/**
, commits are pulled back indev
branch- in the case of a push to
main
, this job will also pull the version bump commit frommain
intodev
- in the case of a push to
- on push to
main
(TODO)gh release
is created
simple-log-ts
npm install @inctasoft/simple-log-ts
Exposes a Log
class that is to be initialized with a correlation_id
string. Once a log instance is created, each log method will also print the correlation_id
.
Useful in event driven apps where each event carries info that you would later want to search for, and correlate with other events.
- applied is
inspect(d, false, 10, false))
on arguments passed - uses
LOGLEVEL
environment variable to decide which log statements are to be printed.
Example usage:
import { Log } from "./log";
const my_correlation_id = {correlation_id: 'some_guid'}
const log = new Log(my_correlation_id);
const my_object = {a:1, b: 'xyz', c: { nested: ['elem1','elem2', 3], more_nested: {d:1, e: '2'} } };
const my_string = 'Lorem ipsum';
const my_number = 42;
log.debug(my_string);
log.info(my_number);
log.warn(my_object);
log.error(my_string);
log.crit(my_number);
result:
{
timestamp: 1696731355442,
level: 'WARN',
correlation: 'some_guid',
data: '{\n' +
' a: 1,\n' +
" b: 'xyz',\n" +
" c: { nested: [ 'elem1', 'elem2', 3 ], more_nested: { d: 1, e: '2' } }\n" +
'}'
}
{
timestamp: 1696731355444,
level: 'ERROR',
correlation: 'some_guid',
data: "'Lorem ipsum'"
}
{
timestamp: 1696731355444,
level: 'CRIT',
correlation: 'some_guid',
data: '42'
}
Notice how only WARN
, ERROR
and CRIT
log statements are printed. This is because process.env.LOGLEVEL
was not set and in this case WARN
level is assumed. See log.spec.ts
for details.
NOTE that both CRIT
and ERROR
levels uses console.error stream. However by setting process.env.LOGLEVEL
to CRIT
one can filter out other errors, leaving only those logged by the crit
method.