anylogger-log4js
Advanced tools
Comparing version 1.1.0-beta.1 to 1.1.0-beta.2
@@ -1,2 +0,4 @@ | ||
export {}; | ||
import { type Adapter } from 'anylogger'; | ||
declare const adapter: Adapter; | ||
export default adapter; | ||
//# sourceMappingURL=anylogger-log4js.d.ts.map |
import anylogger from 'anylogger'; | ||
import log4js from 'log4js'; | ||
// make level numbers compatible with log4js | ||
anylogger.levels = { | ||
trace: 5000, | ||
debug: 10000, | ||
log: 10000, // log4js maps log to debug | ||
info: 20000, | ||
warn: 30000, | ||
error: 40000, | ||
fatal: 50000, | ||
mark: 9007199254740992, // 2^53 | ||
}; | ||
// override anylogger.ext() to make every log method use log4js | ||
anylogger.ext = (logfn) => { | ||
const extension = (logfn) => { | ||
const logger = log4js.getLogger(logfn.name); | ||
for (const level in anylogger.levels) { | ||
logfn[level] = level == 'log' | ||
? ((message, ...args) => logger.debug(message, ...args)) : | ||
((message, ...args) => logger[level](message, ...args)); | ||
? ((message, ...args) => logger.debug(message, ...args)) | ||
: ((message, ...args) => logger[level](message, ...args)); | ||
} | ||
logfn.enabledFor = (level) => { | ||
var arg = level == 'log' ? 'debug' : level; | ||
var result = logger.isLevelEnabled(arg); | ||
return result; | ||
const arg = level == 'log' ? 'debug' : level; | ||
return logger.isLevelEnabled(arg); | ||
}; | ||
return logfn; | ||
}; | ||
const adapter = (anylogger) => { | ||
// make level numbers compatible with log4js | ||
anylogger.levels = { | ||
trace: 5000, | ||
debug: 10000, | ||
log: 10000, // log4js maps log to debug | ||
info: 20000, | ||
warn: 30000, | ||
error: 40000, | ||
fatal: 50000, | ||
mark: 9007199254740992, // 2^53 | ||
}; | ||
// override anylogger.ext() to make every log method use log4js | ||
anylogger.ext = extension; | ||
}; | ||
export default adapter; | ||
// back compat | ||
adapter(anylogger); | ||
//# sourceMappingURL=anylogger-log4js.js.map |
import anylogger, { | ||
type LogFunction, | ||
type LogLevel, | ||
type Logger, | ||
type Extension, | ||
type Adapter, | ||
} from 'anylogger' | ||
import log4js from 'log4js' | ||
// make level numbers compatible with log4js | ||
anylogger.levels = { | ||
trace: 5000, | ||
debug: 10000, | ||
log: 10000, // log4js maps log to debug | ||
info: 20000, | ||
warn: 30000, | ||
error: 40000, | ||
fatal: 50000, | ||
mark: 9007199254740992, // 2^53 | ||
}; | ||
// override anylogger.ext() to make every log method use log4js | ||
anylogger.ext = (logfn: LogFunction): Logger => { | ||
const extension: Extension = (logfn) => { | ||
const logger = log4js.getLogger(logfn.name) | ||
for (const level in anylogger.levels) { | ||
(logfn as Logger)[level as LogLevel] = level == 'log' | ||
? ((message: any, ...args: any[]) => logger.debug(message, ...args)) : | ||
((message: any, ...args: any[]) => logger[level as LogLevel](message, ...args)) | ||
(logfn as Logger)[level] = level == 'log' | ||
? ((message: any, ...args: any[]) => logger.debug(message, ...args)) | ||
: ((message: any, ...args: any[]) => (logger as any)[level](message, ...args)) | ||
} | ||
(logfn as Logger).enabledFor = (level?: LogLevel): boolean | void => { | ||
var arg = level == 'log' ? 'debug' : level | ||
var result = logger.isLevelEnabled(arg) | ||
return result | ||
(logfn as Logger).enabledFor = (level) => { | ||
const arg = level == 'log' ? 'debug' : level | ||
return logger.isLevelEnabled(arg) | ||
} | ||
return logfn as Logger; | ||
} | ||
return logfn as Logger; | ||
}; | ||
const adapter: Adapter = (anylogger) => { | ||
// make level numbers compatible with log4js | ||
anylogger.levels = { | ||
trace: 5000, | ||
debug: 10000, | ||
log: 10000, // log4js maps log to debug | ||
info: 20000, | ||
warn: 30000, | ||
error: 40000, | ||
fatal: 50000, | ||
mark: 9007199254740992, // 2^53 | ||
}; | ||
// override anylogger.ext() to make every log method use log4js | ||
anylogger.ext = extension; | ||
} | ||
export default adapter | ||
// back compat | ||
adapter(anylogger) |
{ | ||
"name": "anylogger-log4js", | ||
"version": "1.1.0-beta.1", | ||
"version": "1.1.0-beta.2", | ||
"description": "Anylogger adapter for log4js", | ||
@@ -22,2 +22,3 @@ "type": "module", | ||
"anylogger-log4js.js.map", | ||
"anylogger-log4js.min.js", | ||
"anylogger-log4js.spec.js", | ||
@@ -56,3 +57,3 @@ "anylogger-log4js.ts" | ||
"devDependencies": { | ||
"anylogger": "^1.1.0-beta.0", | ||
"anylogger": "^1.1.0-beta.3", | ||
"chai": "^5.1.0", | ||
@@ -59,0 +60,0 @@ "cross-env": "^7.0.3", |
@@ -1,2 +0,2 @@ | ||
# anylogger-log4js <sub><sup>1.1.0-beta.1</sup></sub> | ||
# anylogger-log4js <sub><sup>1.1.0-beta.2</sup></sub> | ||
### Anylogger adapter for log4js | ||
@@ -38,3 +38,5 @@ | ||
```js | ||
import 'anylogger-log4js' | ||
import adapter from 'anylogger-log4js' | ||
import anylogger from 'anylogger' | ||
adapter(anylogger) | ||
``` | ||
@@ -46,3 +48,5 @@ | ||
```js | ||
require('anylogger-log4js') | ||
const adapter = require('anylogger-log4js') | ||
const anylogger = require('anylogger') | ||
adapter(anylogger) | ||
``` | ||
@@ -49,0 +53,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17576
11
283
95