Logalize is a JavaScript wrapper for browser's developer console.
- Easily enable/disable logging.
- Namespaces.
- Markdown-like formatting.
Enable or disable logging:
// Disable logalize
logalize.configure({ enabled: false })
// Enable logalize only for yourself (writes to localStorage)
logalize.enable()Methods that work exactly like their console's counterparts:
assertcountdebugalso supports formattingdirdirxmlerroralso supports formatting, see known issuesinfoalso supports formattinglogalso supports formattingtimeStamptracesee known issueswarnalso supports formatting
Also:
group,groupCollapsedandgroupEnd,profileandprofileEndas well astimeandtimeEndsupport lambda syntax:
logalize.group('group1')
myVar = myFunction()
logalize.groupEnd()
/* is the same as */
myVar = logalize.group('group1', myFunction)Also:
logalize('my output')
// is the same as:
logalize.log('my output')logalize.configure({
enabled: true,
enableFormatting: true,
collapseNamespaces: false
})enabled: Defines whether to enable or disable Logalize. When Logalize is disabled, it will not produce any output. However, lambda versions ofprofile,time,groupandnamespacewill still execute given functions. Default:true.enableFormatting: Defines whether formatting should be enabled. Default:true.collapseNamespaces: Defines whether namespaces should usegrouporgroupCollapsedmethod. Defaults tofalse(group).
Namespaces are like groups but more convenient:
/* method 1 */
logalize.namespace('namespace one').log('inside namespace 1')
/* method 2 */
val = logalize.namespace('namespace one', function () {
logalize.log('inside namespace 1')
return 'veryImportantValue'
})You can easily mix methods together and nest namespaces however you want:
logalize.namespace('user login', function () {
logalize.info('user login started')
logalize.namespace('credentials').log('credentials are {correct}.green')
/* code */
logalize.info('[success].green')
})
logalize.namespace('namespace 1').log('some more output')
logalize.namespace('namespace 1', 'another namespace!').log('still nested correctly')Output:
Logalize supports Markdown-like string formatting. Here's the options:
**bold***italic*~strikethrough~_underline_[badge text].classOne.classTwo...(classes are optional){custom text}.classOne.classTwo...(classes are required). This syntax allows you to apply CSS classes to text in curly braces. Available classes are:badge,bold,italic,strikethrough,underlineand color classes.
At the moment, you cannot nest formatting options into each other. Objects and functions are not formattable, but they likely will be in the future.
Logalize supports following color classes (both for badges and normal text):
.blue.orange.red.green.cyan.purple
All styles are declared in a stylesheet and thus are easily extensible.
See index.scss.
At the moment, only these attributes are supported: margin, color, background-color,
border-radius, padding, font-weight, font-style, text-decoration.
-
There's no way to detect when console output happens. Development tools are separate from
windowanddocument, and there is no way to know if the output is happening. So, some output will inevitably get stuck in a group it doesn't belong. -
Stack traces from
logalize.errorandlogalize.tracecontain unneeded information. Sincelogalize.errorandlogalize.tracecall some functions under the hood, the stack trace produced by those functions will contain several unneeded calls.
All of this is according to the author's research. If you know a solution to any of these problems, you're highly encouraged to open an issue and/or a pull request at akxcv/logalize.
Bug reports and pull requests are welcome on GitHub at https://github.com/akxcv/logalize.
The package is available as open source under the terms of the MIT License.
- Support nested formatting
- Log history
- Focus mode (see only the logs you need right now)
- Object and function formatting
