mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
chore: more eslint fallout
This commit is contained in:
parent
335cbeedd7
commit
8db199f08f
@ -1,17 +1,14 @@
|
||||
/* eslint no-underscore-dangle:0 */
|
||||
|
||||
|
||||
|
||||
const debug = require('debug')('log4js:logger');
|
||||
const LoggingEvent = require('./LoggingEvent');
|
||||
const levels = require('./levels');
|
||||
const clustering = require('./clustering');
|
||||
const categories = require('./categories');
|
||||
const configuration = require('./configuration');
|
||||
const debug = require("debug")("log4js:logger");
|
||||
const LoggingEvent = require("./LoggingEvent");
|
||||
const levels = require("./levels");
|
||||
const clustering = require("./clustering");
|
||||
const categories = require("./categories");
|
||||
const configuration = require("./configuration");
|
||||
|
||||
const stackReg = /at (?:(.+)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/;
|
||||
function defaultParseCallStack(data, skipIdx = 4) {
|
||||
const stacklines = data.stack.split('\n').slice(skipIdx);
|
||||
const stacklines = data.stack.split("\n").slice(skipIdx);
|
||||
const lineMatch = stackReg.exec(stacklines[0]);
|
||||
if (lineMatch && lineMatch.length === 6) {
|
||||
return {
|
||||
@ -19,7 +16,7 @@ function defaultParseCallStack(data, skipIdx = 4) {
|
||||
fileName: lineMatch[2],
|
||||
lineNumber: parseInt(lineMatch[3], 10),
|
||||
columnNumber: parseInt(lineMatch[4], 10),
|
||||
callStack: stacklines.join('\n'),
|
||||
callStack: stacklines.join("\n")
|
||||
};
|
||||
}
|
||||
return null;
|
||||
@ -40,7 +37,7 @@ function defaultParseCallStack(data, skipIdx = 4) {
|
||||
class Logger {
|
||||
constructor(name) {
|
||||
if (!name) {
|
||||
throw new Error('No category provided.');
|
||||
throw new Error("No category provided.");
|
||||
}
|
||||
this.category = name;
|
||||
this.context = {};
|
||||
@ -49,11 +46,17 @@ class Logger {
|
||||
}
|
||||
|
||||
get level() {
|
||||
return levels.getLevel(categories.getLevelForCategory(this.category), levels.TRACE);
|
||||
return levels.getLevel(
|
||||
categories.getLevelForCategory(this.category),
|
||||
levels.TRACE
|
||||
);
|
||||
}
|
||||
|
||||
set level(level) {
|
||||
categories.setLevelForCategory(this.category, levels.getLevel(level, this.level));
|
||||
categories.setLevelForCategory(
|
||||
this.category,
|
||||
levels.getLevel(level, this.level)
|
||||
);
|
||||
}
|
||||
|
||||
get useCallStack() {
|
||||
@ -61,7 +64,7 @@ class Logger {
|
||||
}
|
||||
|
||||
set useCallStack(bool) {
|
||||
categories.setEnableCallStackForCategory(this.category, (bool === true));
|
||||
categories.setEnableCallStackForCategory(this.category, bool === true);
|
||||
}
|
||||
|
||||
log(level, ...args) {
|
||||
@ -82,7 +85,7 @@ class Logger {
|
||||
level,
|
||||
data,
|
||||
this.context,
|
||||
(this.useCallStack) && this.parseCallStack(new Error())
|
||||
this.useCallStack && this.parseCallStack(new Error())
|
||||
);
|
||||
clustering.send(loggingEvent);
|
||||
}
|
||||
@ -108,14 +111,16 @@ function addLevelMethods(target) {
|
||||
const level = levels.getLevel(target);
|
||||
|
||||
const levelStrLower = level.toString().toLowerCase();
|
||||
const levelMethod = levelStrLower.replace(/_([a-z])/g, g => g[1].toUpperCase());
|
||||
const levelMethod = levelStrLower.replace(/_([a-z])/g, g =>
|
||||
g[1].toUpperCase()
|
||||
);
|
||||
const isLevelMethod = levelMethod[0].toUpperCase() + levelMethod.slice(1);
|
||||
|
||||
Logger.prototype[`is${isLevelMethod}Enabled`] = function () {
|
||||
Logger.prototype[`is${isLevelMethod}Enabled`] = function() {
|
||||
return this.isLevelEnabled(level);
|
||||
};
|
||||
|
||||
Logger.prototype[levelMethod] = function (...args) {
|
||||
Logger.prototype[levelMethod] = function(...args) {
|
||||
this.log(level, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user