Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@libp2p/logger
Advanced tools
@libp2p/logger is a logging utility designed for use with the libp2p networking stack. It provides a simple and consistent way to log messages across different modules, making it easier to debug and monitor applications built with libp2p.
Creating a Logger
This feature allows you to create a logger instance for a specific module. By providing a module name, you can categorize logs, making it easier to filter and identify logs from different parts of your application.
const logger = require('@libp2p/logger')('my-module');
Logging Messages
The logger instance provides methods like `info`, `error`, `warn`, and `debug` to log messages at different levels of severity. This helps in distinguishing between informational messages, warnings, and errors.
logger.info('This is an info message'); logger.error('This is an error message');
Configuring Log Levels
You can configure the log level for your application using environment variables. This allows you to control the verbosity of logs without changing the code, which is useful for debugging in different environments.
process.env.DEBUG = 'my-module:*';
Winston is a versatile logging library for Node.js that supports multiple transports (e.g., console, file, HTTP) and log levels. Compared to @libp2p/logger, Winston offers more features and flexibility, making it suitable for larger applications with complex logging requirements.
Pino is a fast and low-overhead logging library for Node.js. It is designed for performance and can handle high-throughput logging. While @libp2p/logger is tailored for use with libp2p, Pino is a general-purpose logger that can be used in any Node.js application.
Bunyan is a simple and fast JSON logging library for Node.js. It provides structured logs, which are easy to parse and analyze. Like @libp2p/logger, Bunyan is straightforward to use, but it focuses on JSON output, which can be beneficial for log analysis tools.
A logging component for use in js-libp2p modules
A logger for libp2p based on weald, a TypeScript port of the venerable debug module.
import { logger } from '@libp2p/logger'
const log = logger('libp2p:my:component:name')
try {
// an operation
log('something happened: %s', 'it was ok')
} catch (err) {
log.error('something bad happened: %o', err)
}
log('with this peer: %p', {})
log('and this base58btc: %b', Uint8Array.from([0, 1, 2, 3]))
log('and this base32: %t', Uint8Array.from([4, 5, 6, 7]))
$ DEBUG=libp2p:* node index.js
something happened: it was ok
something bad happened: <stack trace>
with this peer: 12D3Foo
with this base58btc: Qmfoo
with this base32: bafyfoo
$ npm i @libp2p/logger
<script>
tagLoading this module through a script tag will make it's exports available as Libp2pLogger
in the global namespace.
<script src="https://unpkg.com/@libp2p/logger/dist/index.min.js"></script>
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
FAQs
A logging component for use in js-libp2p modules
The npm package @libp2p/logger receives a total of 60,078 weekly downloads. As such, @libp2p/logger popularity was classified as popular.
We found that @libp2p/logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.