forked from SAP/cf-nodejs-logging-support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (61 loc) · 2.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//loading core logger functionality
var coreLogger = require("./cf-nodejs-logging-support-core/log-core");
var effectiveLogger = null;
coreLogger.init();
effectiveLogger = require("./cf-nodejs-logging-support-express/log-express");
defaultConfig = require("./config.js");
effectiveLogger.setCoreLogger(coreLogger);
coreLogger.setConfig(defaultConfig.config);
// Set the minimum logging level. Messages with a lower level, will not be forwarded. (Levels: error, warn, info, verbose, debug, silly)
exports.setLoggingLevel = function (level) {
coreLogger.setLoggingLevel(level);
};
// Sets the given function as log sink. Following arguments will be passed to the sink function: level, output
exports.setSinkFunction = function (func) {
coreLogger.setSinkFunction(func);
};
exports.forceLogger = function (name) {
switch (name) {
//insert your custom framework logger here
case "restify":
effectiveLogger = require("./cf-nodejs-logging-support-restify/log-restify");
break;
case "plainhttp":
effectiveLogger = require("./cf-nodejs-logging-support-plainhttp/log-plainhttp");
break;
default:
effectiveLogger = require("./cf-nodejs-logging-support-express/log-express");
}
effectiveLogger.setCoreLogger(coreLogger);
};
exports.logNetwork = function (req, res, next) {
effectiveLogger.logNetwork(req, res, next);
};
exports.logMessage = function (args) {
coreLogger.logMessage.apply(this, arguments);
};
coreLogger.bindConvenienceMethods(exports);
exports.createWinstonTransport = function (options) {
if (!options) {
options = {
level: 'info'
};
}
options.logMessage = coreLogger.logMessage;
return require("./cf-nodejs-logging-support-winston/winston-transport").createTransport(options);
};
exports.createLogger = function (customFields) {
return coreLogger.createLogger(customFields);
};
exports.registerCustomFields = function(fieldNames) {
return coreLogger.registerCustomFields(fieldNames)
};
exports.setCustomFields = function (customFields) {
return coreLogger.setCustomFields(customFields);
};
exports.setLogPattern = function (args) {
coreLogger.setLogPattern.apply(this, arguments);
};
exports.overrideNetworkField = function (field, value) {
return coreLogger.overrideField(field, value);
};