Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
another-logger
Advanced tools
Lightweight, level-based console wrapper intended for small projects and general-purpose event logging. Yet another console.log
alternative. Inspired by the looks of Yarn.
# yarn
yarn add another-logger
# npm
npm install --save another-logger
To install without installing chalk
(the package used for color support), add --no-optional
to the end of either of these commands.
For usage examples in Javascript and Typescript, see the examples folder.
const log = require('another-logger')(config);
Requiring the module gives a function that can be called to create logger instances. When calling the function, the argument config
is an object with the following properties:
timestamps
- True or false. If true, a timestamp is included in front of all output.
levels
- An object of additional levels to add to the logger. Each key of the object is the name of a logger, and the value should be another object with the following keys:
text
- Custom text to display for this level. If omitted, the name of the level is used (which is sufficient most of the time).
style
- The style to use for displaying this level's name. This can be a function or a string; if it's a string, it will be parsed as a space- and/or period-separated list of chalk
's named styles (red, gray, bgBlue, etc). See that package's README for a full list.
stream
- The stream this log should output to. Overrides the logger setting on a per-level basis.
Note that the levels
object can optionally be passed as a second argument to the function rather than as a key of the main config object. This can be useful if you import config options but want to override the levels per-file, for example.
ignoredLevels
- An object representing levels to ignore. Level names are keys, and values should be truthy if the level is ignore and falsy if not.
Alternatively, an array of level names (strings) can be passed. All levels in the array will be ignored.
These levels will not error, but won't write anything to the console when they're called, either. Useful for debug levels that shouldn't show anything in production.
label
- A label to print along with all output. Note that this can also be specified as a first argument in the constructor; if both are specified, the positional argument takes precedence over the object property.
If you want to reuse configuration options across your project without duplicating them into every file where you create a logger, you can also create a file called logger.config.js
or logger.config.json
in the directory where your project is run. The package will look for this file when creating new loggers and use it as a list of default options. Options specified in this way can still be overridden on a per-logger basis by passing different options to the logger function.
const log = require('another-logger');
The exported function also has all the properties of a logger created with no options, which means that you can use it as a "default" logger. Using the module in this way will still respect options from logger.config.js[on]
.
log.<name>(content...);
Execute a log. name
can be any level name - one of the defaults of debug
, info
, success
, warn
, or error
, or a custom one provided in the logger's config. Content arguments are processed via require('util').format()
which means it works in the same way as console.log
in regards to format strings, object previewing, etc.
log.<name>.trace(content...);
Emulates console.trace
. The same as the normal log, but appends a stack trace to the log output.
log.<name>.table(tabularData, properties?);
Emulates console.table
. Tries to generate and display a table from the object or array tabularData
, displaying only properties whose names are in properties
if it is passed. Logs the argument plainly if a table can't be generated. Throws an error if properties
is given and is not an array of strings. For more information, see the Node.js Console.table
docs.
MIT © eritbh
FAQs
Yet another Node console.log alternative.
The npm package another-logger receives a total of 1 weekly downloads. As such, another-logger popularity was classified as not popular.
We found that another-logger 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.