Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
logda is a lightweight efficient logger thought for developers who use to debug their libraries running in production when something goes wrong, without worrying about global objects or reconfigurations.
Index
Install
npm install logda --save
Create a root logger for your module: (optional but recommended for better log messages)
logger.js
import {logda} from 'logda'
const LOG = logda('my-app')
LOG.info(() => 'Logda log initialized')
export default LOG
The exported LOG is a logda logger already, you can call all level methods on it, but also allows creating sub-loggers by calling the logger method. In this case, the .info call (if info is enabled) will print:
[INFO] my-app> Logda log initialized
Import this root logger to all files requiring a logger: (for example, MyService.js)
MyService.js
import LOG from './logger.js
const log = LOG.logger('MyService')
class MyService {
// ...
aMethod(params) {
log.debug(() => ['aMethod', {params}])
}
}
[DEBUG] my-app|MyService> aMethod {...}
Logda is intended to be used with arrow functions, so to log messages, call the level method with an arrow function:
log.debug(() => 'log messages as simple strings')
log.debug(() => ['log complex data inside an array', {
aKey: 'aValue',
another: calculatedData()
}])
Encapsulating data into an object {} will help you to review it correlating key-valued data in message logs
Logda accepts 'trace', 'debug', 'info', 'warn', 'error', 'off' levels.
Console correspondency:
'off' is intended to disable all logs including 'error' logs.
In your browser's console, write:
window.localStorage.setItem('logda.level', 'debug')
In case that you want a lower level to log messages (Node environments, loc/dev builds, ...), you can enable a specific logda level programmatically:
logger.js
import {logda, setLogdaLevel} from 'logda'
setLogdaLevel('info')
const LOG = logda('my-app')
LOG.info(() => 'Logda log initialized')
export default LOG
In this case, 'Logda log initialized' will be printed directly
In browser environments, the localStorage 'logda.level' (if set) will override the application level
debugLoggingAString => [Console] x 60,989 ops/sec ±1.84% (81 runs sampled)
debugLoggingAString => [Logda] x 2,389,366 ops/sec ±6.53% (78 runs sampled)
debugLoggingAString => [Loglevel] x 2,677,622 ops/sec ±7.42% (75 runs sampled)
debugLoggingAString => [Nightingale] x 1,007,466 ops/sec ±3.80% (81 runs sampled)
debugLoggingObject => [Console] x 18,662 ops/sec ±2.93% (68 runs sampled)
debugLoggingObject => [Logda] x 2,289,789 ops/sec ±6.90% (83 runs sampled)
debugLoggingObject => [Loglevel] x 652,305 ops/sec ±3.71% (86 runs sampled)
debugLoggingObject => [Nightingale] x 442,387 ops/sec ±3.09% (88 runs sampled)
errorLoggingAString => [Console] x 1,564 ops/sec ±6.63% (51 runs sampled)
errorLoggingAString => [Logda] x 1,491 ops/sec ±6.99% (71 runs sampled)
errorLoggingAString => [Loglevel] x 1,561 ops/sec ±6.47% (50 runs sampled)
errorLoggingAString => [Nightingale] x 22,158 ops/sec ±2.92% (76 runs sampled)
errorLoggingObject => [Console] x 799 ops/sec ±6.07% (63 runs sampled)
errorLoggingObject => [Logda] x 776 ops/sec ±6.31% (76 runs sampled)
errorLoggingObject => [Loglevel] x 810 ops/sec ±3.60% (57 runs sampled)
errorLoggingObject => [Nightingale] x 889 ops/sec ±10.71% (67 runs sampled)
Logda is intended to be blazing fast when the logging level is disabled, as it does not run the log operation, neither any operation needed to build the log message, in that case.
Fast analysis of the benchmark results:
Note: To run the benchmarks, just clone the repo and run:
npm run benchmark
Feel free to include new loggers to the benchmarks :)
:wrench: Maintenance info
npm run...
Use the PR template to explain the better possible:
This project uses Travis CI for:
To create a new Release, take in mind:
FAQs
Efficient lightweight logger
We found that logda demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.