How to use the levels function from loglevel

Find comprehensive JavaScript loglevel.levels code examples handpicked from public code repositorys.

loglevel.levels is an object that contains the predefined levels of log messages that can be used with the loglevel package.

106
107
108
109
110
111
112
113
114
115
* A `log.setLevel(level, [persist])` 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_
  * As a numeric index from 0 (trace) to 5 (silent) ← _deliciously terse, and more easily programmable (...although, why?)_

  Where possible the log level will be persisted. LocalStorage will be used if available, falling back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass `false` as the optional 'persist' second argument, persistence will be skipped.
fork icon170
star icon0
watch icon4

+ 3 other calls in file

142
143
144
145
146
147
148
149
150
151
// Estimate gas cost
const gas_eta = await land_nft.tokenURI.estimateGas(token_id, {gas: MAX_UINT64});
log.info(`Estimated gas amount for ${token_id} SVG generation: ${gas_eta}`);

// Log Resource sites info
if(log.getLevel() <= log.levels.DEBUG) {
	const resource_sites = plot.sites;
	log.debug("Site list:");
	for(const site of resource_sites) {
		log.debug(`Resource type: ${site.typeId} (${site.typeId < 4? "element": "fuel"})`);
fork icon0
star icon1
watch icon2

How does loglevel.levels work?

loglevel.levels is an array of predefined levels used to set the logging level of a loglevel logger instance. The levels are ordered by severity from least to most: "trace", "debug", "info", "warn", and "error". Each level is assigned a numerical value, with the higher the level, the greater the numerical value. The default level is "info", and setting a logging level equal to or higher than the current level will result in the message being logged.

54
55
56
57
58
59
60
61
62
63
    return git.cwd(this.questDirectory)
        .exec(git.clone('remote.git', `quest${this.questId}`));
}

displayInstructions() {
    if (log.getLevel() > log.levels.DEBUG) {
        console.clear();
    }

    log.info(`Setup GitQuest #${this.questId}.....OK\n`);
fork icon0
star icon0
watch icon0

0
1
2
3
4
5
6
7
8
9
10
11
12
const log = require("loglevel")
const MQTT = require("async-mqtt")
const RikaStove = require('./RikaStove')
const loadConf = require('./loadConf')


log.setDefaultLevel(log.levels[process.env.LOG_LEVEL?.toUpperCase()] ?? log.levels.INFO)


const main = async () => {



fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
11
const log = require("loglevel");

// Override default log levels with custom levels
log.setLevel(log.levels.INFO);

// Log messages at various levels
log.trace("This is a trace message");
log.debug("This is a debug message");
log.info("This is an info message");
log.warn("This is a warning message");
log.error("This is an error message");

In the example above, we set the log level to INFO using the log.setLevel() method and then log messages at various levels using the log instance's trace(), debug(), info(), warn(), and error() methods. The loglevel.levels object is used internally by the log.setLevel() method to set the appropriate numerical value for the specified log level.