See cnsl README.md.
magnal / cnsl Goto Github PK
View Code? Open in Web Editor NEWLogger for javascript projects. Wraps console methods and provides additional features, like buffered groups.
License: MIT License
Logger for javascript projects. Wraps console methods and provides additional features, like buffered groups.
License: MIT License
See cnsl README.md.
The more cnsl is used within an application, the more logs are shown in the browser console. To have the ability to only show logs for specific parts of the application.
The scope could be added for each cnsl call or per file/class.
cnsl(CnslScopes.ANY_SCOPE).log(...);
cnsl(CnslScopes.ANY_SCOPE).log(...);
// or
cnsl = cnsl(CnslScopes.ANY_SCOPE);
cnsl.log(...);
cnsl.log(...);
This scope (or array of scopes) could be shown in the console to have the ability to filter it. Next step could be a api to only activate specific scopes.
When cnsl is used, the information about the caller file and line number looks like this...
It is not shown which file called the log message. According to this SO answer it should be possible to correct this behavior:
https://stackoverflow.com/questions/13815640/a-proper-wrapper-for-console-log-with-correct-line-number/32928812#32928812
Due to the buffered logs we lost the ability to have groups in groups. Console api supports groups in groups, which is a nice feature. It should be supported from cnsl as well.
@cnslClass() // tracks instances of classes (limit of # of instances can be passed, shows warn and error if limit is reached)
export class SampleClass
{
@cnsl()
private cnsl:Cnsl;
constructor()
{
// scoped cnsl
this.cnsl;
// global cnsl
cnsl;
// create scoped cnsl manually
let anotherScopeCnsl:Cnsl = cnsl.scoped();
}
@cnslMethod() // tracks params and return values, counts number of runs, show warn and error when limit is reached
public anyMethod(param:string, @cnslGroup('') cnsl:Cnsl):string
{
this.cnsl.group((cnsl:Cnsl) =>
{
});
cnsl.group((cnsl:Cnsl) => {
cnsl;
});
}
}
cnsl
is setting up cnsl instance with the scope of the current class.
cnslGroup
is setting up a cnsl group instance with the scope of the current class and method (group opens on method start and closes on method end).
cnslClass
is tracking instances of the class.
cnslMethod
is tracking calls of the method.
What I have in mind is something like this:
cnsl.group('This is my group name', (cnsl:Cnsl) =>
{
cnsl.debug('Grouped debug log');
});
Group creation and completion is done automatically, it's easier to use and it looks nicer.
Update:
Additionally, the api could be changed to enable collapsed groups via a flag or config object:
cnsl.group('This is my group name', true, (cnsl:Cnsl) =>
{
cnsl.debug('Grouped debug log');
});
// or
cnsl.group('This is my group name', {collapsed: true}, (cnsl:Cnsl) =>
{
cnsl.debug('Grouped debug log');
});
By adding a lambda function as a additional parameter to group/groupCollapsed, we could add handling for wrapped console groups.
class Foo {
myBar() {
cnsl.group('This is my group', (cnsl:Cnsl) => {
...
cnsl.log();
...
});
}
}
Needed?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.