@lapita/loggy
v0.0.2
Published
[]() [](https://github.com/prettier/prettier) [;
// Instance loggy
export const {debug, log, info, warn, error} = createLoggy(
{
global: 'global stuff',
auth: 'authorization',
dashboard: 'dashboard'
}
);
Loggy wraps five log levels. From lower to higher level, you'll find debug, log, info, warn and error. There can be easily access by destructuring the return object. And you're ready to start using Loggy.
log.global('It preserves the line numbers', {obj: 'test'});
log.auth('auth failed');
log.dashboard('dashboard init');
Your IDE will suggest the available groups as soon as you type log.
.
Logging a property can be done by adding a @LoggyProperty
. You need to pass in a function pointing to the log and group you want to use. This way, you'll be preserving the line and file where the property lays.
@LoggyProperty((t) => log.global(t), {logValue: true, accessType: 'set'})
title = 'Loggy! Open the console.';
This decorator admits the following options, which are self-explanatory.
{
logCalls: boolean;
logValue: boolean;
accessType: 'get' | 'set' | 'get/set';
enable: boolean;
}
Logging a method can be done by adding a @LoggyMethod
. You need to pass in a function pointing to the log and group you want to use as well.
@LoggyMethod((t) => log.global(t))
testMethod() {
for (let index = 0; index < 1000000; index++) {
const text = String(index);
const number = +text;
}
}
This decorator admits the following options, which, again, are pretty self-explanatory.
{
logTime: true,
logCalls: false,
logContext: false,
enable: true,
}
Addionally, it is possible to customize the log level colors as well as the separator between the group name and the actually log text. You need to pass in another argument while creating a new instace of Loggy.
{
separator: '#',
debug: 'background: white; color: black;',
log: 'background: purple; color: white;',
info: 'background: blue; color: white;',
warn: 'background: orange; color: black;',
error: 'background: red; color: white;',
};