How to use the setLevel function from loglevel
Find comprehensive JavaScript loglevel.setLevel code examples handpicked from public code repositorys.
loglevel.setLevel is a function that sets the log level of the loglevel logger.
11 12 13 14 15 16 17 18 19
## Features ### Simple * Log things at a given level (trace/debug/info/warn/error) to the console object (as seen in all modern browsers & node.js) * Filter logging by level (all the above or 'silent'), so you can disable all but error logging in production, and then run log.setLevel("trace") in your console to turn it all back on for a furious debugging session * Single file, no dependencies, weighs in at 1.1KB minified and gzipped ### Effective
+ 7 other calls in file
80 81 82 83 84 85 86 87 88 89
These methods should never fail in any environment, even if no console object is currently available, and should always fall back to an available log method even if the specific method called (e.g. warn) isn't available. * A `log.setLevel(level)` method. This disables all logging below the given level, so that after a log.setLevel("warn) call log.warn("something") or log.error("something") will output messages, but log.info("something") will not. This can take either a log level name or 'silent' (which disables everything) in one of a few forms: * As a log level from the internal levels list, e.g. log.levels.SILENT ← _for type safety_ * As a string, like 'error' (case-insensitive) ← _for a reasonable practical balance_
+ 7 other calls in file
How does loglevel.setLevel work?
loglevel.setLevel
works by taking a single input, which is the log level to set.
The function sets the log level of the loglevel
logger to the specified level.
Log levels range from 0 (trace) to 5 (silent), with each level suppressing logs of lower severity.
For example, if the log level is set to 3 (error), all logs with severity levels of 0 (trace), 1 (debug), and 2 (info) will be suppressed.
By using loglevel.setLevel
, you can control the amount of logging output from your application, allowing you to focus on specific levels of severity as needed.
13 14 15 16 17 18 19 20 21 22
ERROR: chalk.red, }; logPrefix.reg(log); log.enableAll(); if (process.env.LOGLEVEL === 'DEBUG') { log.setLevel(log.levels.DEBUG); } else { log.setLevel(log.levels.INFO); } logPrefix.apply(log, {
GitHub: orlopau/ds-wrapper
10 11 12 13 14 15 16 17 18 19 20
module.exports = function(ds_ip, log_level) { if(ds_ip === null || ds_ip === undefined){ throw "No DSS IP specified in constructor!"; } if (log_level) { log.setLevel(log_level); } let module = {};
Ai Example
1 2 3 4 5 6 7 8 9 10 11
const log = require("loglevel"); // Set the log level to "info" log.setLevel("info"); // Log some messages at various severity levels log.trace("This message will not be logged"); log.debug("This message will not be logged"); log.info("This message will be logged"); log.warn("This message will be logged"); log.error("This message will be logged");
In this example, we first require the loglevel library and create a new log instance. We then set the log level of the logger to 'info' using the log.setLevel function. We then log messages at various severity levels using log.trace, log.debug, log.info, log.warn, and log.error. Because the log level was set to 'info', messages with severity levels of 'trace' and 'debug' will not be logged, while messages with severity levels of 'info', 'warn', and 'error' will be logged. The resulting output demonstrates how loglevel.setLevel can be used to set the log level of the loglevel logger.
96 97 98 99 100 101 102 103 104 105
hotCtx('./log').setLogLevel(level); } switch (level) { case INFO: case ERROR: log.setLevel(level); break; case WARNING: // loglevel's warning name is different from webpack's log.setLevel('warn');
57 58 59 60 61 62 63 64 65 66
function debug (msg) { const mparsed = parseMsg(msg) mlog.debug(mparsed.full) } function setLevel (level) { mlog.setLevel(level) } function getLevel () { return mlog.getLevel()
5 6 7 8 9 10 11 12 13
const BundleSizeBot = require('./BundleSizeBot'); function runOnce() { log.enableAll(); log.info(`[${new Date().toString()}] Starting BundleSizeBot`); log.setLevel(argv.logLevel || 'error'); const bsb = new BundleSizeBot(); bsb.run(); }
1 2 3 4 5 6 7 8 9 10 11 12
// test running (async () => { try { log.setLevel(0) log.trace('trace') log.debug('debug') log.info('info')
34 35 36 37 38 39 40 41 42 43
}, options ) log.setDefaultLevel('error') log.setLevel(options.logLevel) const bus = new EventBus(log) if (!options.url) {
GitHub: TanukiHQ/Genkan
114 115 116 117 118 119 120 121 122 123
format(level, name, timestamp) { return chalk.red.bold(`[${timestamp}] ${level} ${name}:`) }, }) if (config.debugMode === true) { log.setLevel('debug', true) } else { log.setLevel('info', true) }
4 5 6 7 8 9 10 11 12 13 14 15
const path = require('path') const log = require('loglevel') const execSync = require('child_process').execSync log.setLevel('info') // log.setLevel('debug') // download_url = "https://www.rstudio.com/products/rstudio/download/preview/" // old rstudio preview page download_url = "https://posit.co/download/rstudio-desktop/"
+ 4 other calls in file
GitHub: andystevenson/lib
62 63 64 65 66 67 68 69 70 71 72 73
} raw.apply(undefined, messages) } } process.env.DEBUG ? log.setLevel('TRACE') : log.setLevel('INFO') return { log } }
+ 6 other calls in file
8 9 10 11 12 13 14 15 16 17 18 19 20
function setup(options) { options = options || {}; app.locals.app_name = options.APP_NAME || 'gp-connect-update-record-fhir'; app.locals.version_info = JSON.parse(options.VERSION_INFO || '{}'); log.setLevel(options.LOG_LEVEL || "info"); log.info(JSON.stringify({ timestamp: Date.now(),
42 43 44 45 46 47 48 49 50 51
let specifiedLocale; for (const arg of process.argv.slice(2)) { if (arg === '--fix') { fix = true; } else if (arg === '--quiet') { log.setLevel('error'); } else { specifiedLocale = arg; } }
loglevel.debug is the most popular function in loglevel (1470 examples)