
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Logdown is a JavaScript logging library that provides a simple and colorful way to log messages in the browser console. It supports different log levels, custom prefixes, and styles to make debugging easier and more visually appealing.
Basic Logging
Logdown allows you to create a logger instance with a custom prefix and log messages to the console.
const logger = require('logdown')('myLogger');
logger.log('This is a log message');
Log Levels
Logdown supports different log levels such as info, warn, and error to categorize the importance of messages.
const logger = require('logdown')('myLogger');
logger.info('This is an info message');
logger.warn('This is a warning message');
logger.error('This is an error message');
Custom Styles
You can customize the appearance of log messages by setting styles such as prefix color and markdown support.
const logger = require('logdown')('myLogger');
logger.state = { prefixColor: 'blue', markdown: false };
logger.log('This is a styled log message');
Grouping Logs
Logdown allows you to group related log messages together, making it easier to organize and read logs.
const logger = require('logdown')('myLogger');
logger.group('Group 1');
logger.log('Message inside group 1');
logger.groupEnd('Group 1');
Winston is a versatile logging library for Node.js that supports multiple transports, log levels, and formats. Unlike Logdown, Winston is more suitable for server-side logging and offers advanced features like log rotation and custom transports.
Bunyan is another powerful logging library for Node.js that focuses on JSON logging. It provides a simple API, log levels, and supports streams for log output. Bunyan is more geared towards server-side applications and structured logging compared to Logdown's browser-focused approach.
Pino is a fast and lightweight logging library for Node.js that emphasizes performance. It supports log levels, custom serializers, and transports. Pino is designed for high-performance server-side logging, whereas Logdown is more focused on providing a colorful and user-friendly logging experience in the browser.
Logdown is a debug utility for the browser and the server with Markdown support. It does not have any dependencies and is only 2K gzipped.
You can see it in action in the example page or in the preview below.
The simplest use of the library in both platforms could be done as follows:
If on the server, install it through npm:
npm install --save logdown
var Logdown = require('logdown')
var logger = new Logdown({prefix: 'foo'})
In the browser you can install it through Bower.
bower install logdown
var logger = new Logdown({prefix: 'foo'})
Using the dynamic module loader SystemJS, Logdown can be loaded as a CommonJS module.
SystemJS.config({
map: {
'logdown': 'bower_components/logdown/dist/index.js'
},
packages: {
'logdown': {format: 'cjs'}
}
});
System.import('logdown').then(function(Logdown) {
var logger = new Logdown({prefix: 'foo'}
});
You can also use the lib in the browser in the same way as in the server if you
use Browserify. Or you can just download it
here and put the
dist/index.js
file in your public folder.
It is highly recommended to use a prefix for your instance, this way you get a nice prefixed message on console and it is possible to silence instances based on the prefix name, as we will see after.
After creating your object, you can use the regular log
, warn
, info
and error
methods as we have on console
, but now with Markdown support.
logger.log('lorem *ipsum*')
logger.info('dolor _sit_ amet')
logger.warn('consectetur `adipiscing` elit')
You can pass multiple arguments
logger.log('lorem', '*ipsum*')
logger.info('dolor _sit_', 'amet')
logger.warn('consectetur', '`adipiscing` elit')
The constructor accepts one object for configuration on instantiation time.
opts.prefix
Type: 'String'
Default: ''
var logger = new Logdown({prefix: 'foo'})
logger.log('Lorem ipsum') // Will use console.log with a prefix
You should use the name of your module.
You can, also, use :
to separate modules inside one big module.
var fooBarLogger = new Logdown({prefix: 'foo:bar'})
fooBarLogger.log('Lorem ipsum')
var fooQuzLogger = new Logdown({prefix: 'foo:quz'})
fooQuzLogger.log('Lorem Ipsum')
opts.markdown
Type: 'Boolean'
Default: true
If setted to false
, markdown will not be parsed.
var logger = new Logdown({markdown: false})
logger.log('Lorem *ipsum*') // Will not parse the markdown
For Markdown, the following mark-up is supported:
// Bold with "*"" between words
logger.log('lorem *ipsum*')
// Italic with "_" between words
logger.log('lorem _ipsum_')
// Code with ` (backtick) between words
logger.log('lorem `ipsum`')
opts.alignOutput
Type: 'Boolean'
Default: false
If setted to true
, the name of the logger instance will have the same length as the longest name of any other Logdown instance.
It is possible to enable/disable the output of instances using the
Logdown.disable
or Logdown.enable
methods.
Logdown.disable('foo') // will disable the instance with *foo* prefix
Logdown.enable('bar') // will enable the instance with *bar* prefix
You can also use wildcards.
Logdown.enable('*') // enables all instances
Logdown.disable('*') // disables all instances
Logdown.enable('foo*') // enables all instances with a prefix starting with *foo*
Use -
to do a negation.
// enables all instances but the one with *foo* prefix
Logdown.enable('*', '-foo')
// disables all intances with foo in the prefix, but don't disable *foobar*
Logdown.disable('*foo*', '-foobar')
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
---|---|---|---|---|---|---|
Latest | 9+ | Latest | Latest | Latest | Latest | Latest |
| |
|
|
|
|
|
|
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Latest | 6+ | 4.0+ | 8+ | Latest | Latest | Latest |
![]() |
---|
0.10+ ✔ |
143 Caio Gondim
4 David Godfrey
2 Sven Anders Robbestad
1 Dan Lukinykh
1 Bent Cardan
1 Gleb Bahmutov
1 netmml
If you found this library useful and are willing to donate, transfer some
bitcoins to 1BqqKiZA8Tq43CdukdBEwCdDD42jxuX9UY
or through the
URL https://www.coinbase.com/caiogondim
Or via PayPal.me https://www.paypal.me/caiogondim.
caiogondim.com · GitHub @caiogondim · Twitter @caio_gondim
FAQs
Debug utility with markdown support that runs on browser and server
The npm package logdown receives a total of 128,329 weekly downloads. As such, logdown popularity was classified as popular.
We found that logdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.