mirror of
https://github.com/appium/appium.git
synced 2026-05-12 22:08:40 -05:00
log stripColors fix
This commit is contained in:
+22
-3
@@ -30,8 +30,21 @@ var timestamp = function () {
|
||||
return date.toFormat("YYYY-MM-DD HH24:MI:SS:LL");
|
||||
};
|
||||
|
||||
// Strip the color marking within messages.
|
||||
// We need to patch the transports, because the stripColor functionality in
|
||||
// Winston is wrongly implemented at the logger level, and we want to avoid
|
||||
// having to create 2 loggers.
|
||||
function applyStripColorPatch(transport) {
|
||||
var _log = transport.log.bind(transport);
|
||||
transport.log = function (level, msg, meta, callback) {
|
||||
var code = /\u001b\[(\d+(;\d+)*)?m/g;
|
||||
msg = ('' + msg).replace(code, '');
|
||||
_log(level, msg, meta, callback);
|
||||
};
|
||||
}
|
||||
|
||||
var _createConsoleTransport = function (args, logLvl) {
|
||||
return new (winston.transports.Console)({
|
||||
var transport = new (winston.transports.Console)({
|
||||
name: "console"
|
||||
, timestamp: args.logTimestamp ? timestamp : undefined
|
||||
, colorize: !args.logNoColors
|
||||
@@ -40,10 +53,12 @@ var _createConsoleTransport = function (args, logLvl) {
|
||||
, json: false
|
||||
, level: logLvl
|
||||
});
|
||||
if (args.logNoColors) applyStripColorPatch(transport);
|
||||
return transport;
|
||||
};
|
||||
|
||||
var _createFileTransport = function (args, logLvl) {
|
||||
return new (winston.transports.File)({
|
||||
var transport = new (winston.transports.File)({
|
||||
name: "file"
|
||||
, timestamp: timestamp
|
||||
, filename: args.log
|
||||
@@ -54,6 +69,8 @@ var _createFileTransport = function (args, logLvl) {
|
||||
, level: logLvl
|
||||
}
|
||||
);
|
||||
applyStripColorPatch(transport);
|
||||
return transport;
|
||||
};
|
||||
|
||||
var _createWebhookTransport = function (args, logLvl) {
|
||||
@@ -66,7 +83,7 @@ var _createWebhookTransport = function (args, logLvl) {
|
||||
port = parseInt(hostAndPort[1], 10);
|
||||
}
|
||||
|
||||
return new (winston.transports.Webhook)({
|
||||
var transport = new (winston.transports.Webhook)({
|
||||
name: "webhook"
|
||||
, host: host || '127.0.0.1'
|
||||
, port: port || 9003
|
||||
@@ -76,6 +93,8 @@ var _createWebhookTransport = function (args, logLvl) {
|
||||
, json: false
|
||||
, level: logLvl
|
||||
});
|
||||
applyStripColorPatch(transport);
|
||||
return transport;
|
||||
};
|
||||
|
||||
var _createTransports = function (args) {
|
||||
|
||||
Reference in New Issue
Block a user