How to use the warn function from loglevel
Find comprehensive JavaScript loglevel.warn code examples handpicked from public code repositorys.
loglevel.warn is a function provided by the loglevel library that logs a warning message to the console.
56 57 58 59 60 61 62 63 64 65
### AMD (e.g. RequireJS) ```javascript define(['loglevel'], function(log) { log.warn("dangerously convenient"); }); ``` ### Directly in your web page:
+ 3 other calls in file
883 884 885 886 887 888 889 890 891 892
ltype.pattern.push(curr.value); curr = scanner.next(); break; case 0: log.debug('}'); if(length > 0 && length !== ltype.pattern.length) log.warn('lengths do not match on LTYPE pattern'); ltypes[ltypeName] = ltype; ltype = {}; log.debug('LType {'); curr = scanner.next();
How does loglevel.warn work?
loglevel.warn()
is a method in the loglevel library that is used to log a warning message to the console with a warning icon. It takes a string or an object as an argument and logs it with a prefix of the word "WARN". The warning message is printed to the console only if the logging level is set to "warn" or lower.
258 259 260 261 262 263 264 265 266 267
### AMD ```javascript define(['loglevel', 'loglevel-plugin-remote'], function(log, remote) { remote.apply(log); log.warn('message'); }); ``` ## Example
GitHub: cxw42/TabFern
133 134 135 136 137 138 139 140 141 142
let val; try { val = JSON.parse(String(obj[key])); } catch(e) { let m = `Non-JSON value for ${key} - skipping`; log.warn(m); stash(m); ok = false; continue; }
+ 35 other calls in file
Ai Example
1 2 3 4
import log from "loglevel"; log.setLevel("warn"); log.warn("This is a warning message");
In this example, we first import the loglevel library and set the log level to 'warn' using the setLevel method. We then call the warn method on the log object to log a warning message.
105 106 107 108 109 110 111 112 113 114
* Client video stream error handler. * * @param {Error} error Camera stream error. */ onVideoStreamError(error) { log.warn('Can\'t start client video stream', error); } /** * Stop client webcam video stream.
154 155 156 157 158 159 160 161 162 163
this.phoneTesseract = await this.createTesseractWorker(4, 'eng', this.phoneTimeTesseractOptions); } async initializeTimeRemainingTesseract() { if (!!this.timeRemainingTesseract) { log.warn('Reinitializing time remaining tesseract worker...'); await this.timeRemainingTesseract.terminate(); } this.timeRemainingTesseract = await this.createTesseractWorker(4, 'eng', this.timeRemainingTesseractOptions);
+ 4 other calls in file
538 539 540 541 542 543 544 545 546 547 548
// Unmount volume root execFileSync('umount', [volume_root]) } catch (err) { // Failure log.warn(`Couldn't unmount volume root '${volume_root}': ${err.toString()}`) } } }
+ 244 other calls in file
303 304 305 306 307 308 309 310 311 312
dxf.tables = parseTables(); log.debug('<'); } else if(curr.value === 'EOF') { log.debug('EOF'); } else { log.warn('Skipping section \'%s\'', curr.value); } } else { curr = scanner.next(); }
141 142 143 144 145 146 147 148 149 150
'content-changed': function contentChanged() { log.info('[WDS] Content base changed. Reloading...'); self.location.reload(); }, warnings: function warnings(_warnings) { log.warn('[WDS] Warnings while compiling.'); var strippedWarnings = _warnings.map(function (warning) { return stripAnsi(warning); }); sendMsg('Warnings', strippedWarnings);
235 236 237 238 239 240 241 242 243 244 245
/** * @param {number} distance in meters (> 0) */ Hexapod.prototype.goForward = function(distance){ if(distance > 0) this.pushCmd({name:'goForward', args:[distance]}); else log.warn("goForward: argument must be greater than zero!") } /** * @param {number} distance in meters (> 0)
+ 5 other calls in file
1 2 3 4 5 6 7 8 9 10 11 12
const logger = require('loglevel') const { green, red, yellow } = require('kleur') let logLevel = process.env.LOG_LEVEL || 'info' if (!['trace', 'debug', 'info', 'warn', 'error'].includes(logLevel)) { logger.warn(`Invalid loglevel specified (${logLevel}). Defaulting to 'info'.`) logLevel = 'info' } const originalFactory = logger.methodFactory
+ 3 other calls in file
6 7 8 9 10 11 12 13 14 15
log.setLevel(0) log.trace('trace') log.debug('debug') log.info('info') log.warn('warn', 'kjhgfbdcxz') log.error('error') console.log(log.getLevel()) console.log(log.levels)
462 463 464 465 466 467 468 469 470 471 472 473
.map((tip) => (u.isObject(tip) ? tip.msg : tip)) .map((tip) => `[require-extension-vue: compiler tip] ${tip}`) .filter(templateCompilerTipMessageFilter); if (tips.length > 0) { log.warn(`[require-extension-vue] compiler tips in file: ${filename}`); } tips.forEach((tip) => log.warn(tip)); };
4 5 6 7 8 9 10 11 12 13 14 15
loglevel.setLevel(parseInt(process.env.LOG_LEVEL || 0)); const trace = loglevel.trace; const debug = loglevel.debug; const info = loglevel.info; const warn = loglevel.warn; const error = loglevel.error; loglevel.trace = function (a, b) { trace(b === undefined ? a : a + ' | ' + b);
33 34 35 36 37 38 39 40 41 42
let questDirectoryParent = path.join(this.questDirectory, '..') cd(questDirectoryParent); if (test('-d', this.questDirectory)) { log.warn(`Remove existing directory: ${this.questDirectory}`) rm('-rf', this.questDirectory); } mkdir(this.questDirectory); }
GitHub: PHaroZ/rika-mqtt
32 33 34 35 36 37 38 39 40 41
try { status = await stove.getStatus() log.trace(status) } catch (e) { log.warn('fail to get status') log.warn(e) } try { await mqtt.publish(conf.mqtt.topicOut, JSON.stringify(status)) log.trace(`message published to ${conf.mqtt.topicOut}`)
+ 3 other calls in file
loglevel.debug is the most popular function in loglevel (1470 examples)