logalize
v0.0.7
Published
A better window.console
Downloads
656
Maintainers
Readme
Logalize
Logalize is a JavaScript wrapper for browser's developer console.
Main features
- Easily enable/disable logging.
- Namespaces.
- Markdown-like formatting.
Usage
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:
assert
count
debug
also supports formattingdir
dirxml
error
also supports formatting, see known issuesinfo
also supports formattinglog
also supports formattingtimeStamp
trace
see known issueswarn
also supports formatting
Also:
group
,groupCollapsed
andgroupEnd
,profile
andprofileEnd
as well astime
andtimeEnd
support 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')
Configuration options
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
,group
andnamespace
will still execute given functions. Default:true
.enableFormatting
: Defines whether formatting should be enabled. Default:true
.collapseNamespaces
: Defines whether namespaces should usegroup
orgroupCollapsed
method. Defaults tofalse
(group
).
Namespaces
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:
Formatting
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
,underline
and 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.
Color classes
Logalize supports following color classes (both for badges and normal text):
.blue
.orange
.red
.green
.cyan
.purple
Adding custom / overriding existing styles
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
.
Known issues
There's no way to detect when console output happens. Development tools are separate from
window
anddocument
, 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.error
andlogalize.trace
contain unneeded information. Sincelogalize.error
andlogalize.trace
call 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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/akxcv/logalize.
License
The package is available as open source under the terms of the MIT License.
TODO
- Support nested formatting
- Log history
- Focus mode (see only the logs you need right now)
- Object and function formatting