
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, providing a single interface and a similar behavior between the browser and the server.
It doesn't have any dependencies for the browser version and it's only 2K gzipped.
You can see it in action in the example page or in the preview below.
$ npm install --save logdown
Out-of-the box colors work well on both light and dark themes.
logdown
exports a function. For the simplest use case, pass the name of your module and
it will return a decorated console
.
const logdown = require('logdown')
const logger = logdown('foo')
Or in a more idiomatic way:
const logger = require('logdown')('foo')
Just like debug.js and node core's debuglog, the enviroment variable NODE_DEBUG
is used to decide which
module will print debug information.
$ NODE_DEBUG=foo node example/node.js
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. If a method is not provided by logdown
, it will
just delegate to the original console
object or opts.logger
if passed.
logger.log('lorem *ipsum*')
logger.info('dolor _sit_ amet')
logger.warn('consectetur `adipiscing` elit')
As the native APIs, multiple arguments are supported.
logger.log('lorem', '*ipsum*')
logger.info('dolor _sit_', 'amet')
logger.warn('consectetur', '`adipiscing` elit')
The following options can be used for configuration.
prefix
String
const logger = logdown('foo')
logger.log('Lorem ipsum')
var fooBarLogger = logdown('foo:bar')
fooBarLogger.log('Lorem ipsum')
var fooQuzLogger = logdown('foo:quz')
fooQuzLogger.log('Lorem Ipsum')
markdown
Boolean
true
If setted to false
, markdown will not be parsed.
var logger = 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`')
prefixColor
String
logdown.prefixColors
array.Hex value for a custom color.
const logger1 = logdown('foo', { prefixColor: '#FF0000' }) // red prefix
const logger2 = logdown('bar', { prefixColor: '#00FF00' }) // green prefix
const logger3 = logdown('quz', { prefixColor: '#0000FF' }) // blue prefix
logger
console
Custom logger. On Node it's possible to instantiate a new console
setting it's output to a
different stream other than stdout
and stderr
.
const output = fs.createWriteStream('./stdout.log');
const errorOutput = fs.createWriteStream('./stderr.log');
const fileLogger = new Console(output, errorOutput)
const logger = logdown('foo', {
logger: fileLogger
})
isEnabled
localStorage.debug
on browser and from env var NODE_DEBUG
on node.Used to enable/disable a given instance at runtime.
// Prevents `logger` to output debug info
logger.state.isEnabled = false
logdown
is compatible with Node.js
util.debuglog and
debug.js as it uses the NODE_DEBUG
enviroment variable to
control which instances are enabled to output debug info.
For the browser use localStorage.debug
.
NODE_DEBUG=foo node foo.js # will disable the instance with *foo* prefix
localStorage.debug = 'foo'
Multiple instances should be separated by comma
NODE_DEBUG=foo,bar node foo.js # will disable the instance with *foo* prefix
localStorage.debug = 'foo,bar'
Wildcard *
is supported.
NODE_DEBUG=* node foo.js # enables all instances
NODE_DEBUG=foo* node foo.js # enables all instances with a prefix starting with *foo*
Use -
to do a negation.
# enables all instances but the one with *foo* prefix
NODE_DEBUG=*,-foo node foo.js
# disables all intances with foo in the prefix, but don't disable *foobar*
NODE_DEBUG=*foo*,-foobar node foo.js
If you're using this in one or more of your libraries, you should use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you should prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser".
If you found this library useful and are willing to donate, transfer some
bitcoins to 1BqqKiZA8Tq43CdukdBEwCdDD42jxuX9UY
.
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.