forked from applitools/Eyes.Selenium.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileLogHandler.js
More file actions
140 lines (121 loc) · 2.97 KB
/
Copy pathFileLogHandler.js
File metadata and controls
140 lines (121 loc) · 2.97 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
---
name: FileLogHandler
description: Write log massages to the browser/node console
provides: [FileLogHandler]
requires: [winston]
---
*/
(function () {
"use strict";
var winston = require('winston'),
timeStringFn = require('eyes.sdk').ConsoleLogHandler.getTimeString;
/**
*
* C'tor = initializes the module settings
*
* @param {Boolean} isVerbose
*
**/
function FileLogHandler(isVerbose) {
this._isVerbose = !!isVerbose;
this._appendToFile = true;
this._fileName = "eyes.log";
this._fileDirectory = "./";
}
/**
* Whether to handle or ignore verbose log messages.
*
* @param {Boolean} isVerbose
*/
FileLogHandler.prototype.setIsVerbose = function (isVerbose) {
this._isVerbose = !!isVerbose;
};
/**
* Whether to handle or ignore verbose log messages.
*
* @return {Boolean} isVerbose
*/
FileLogHandler.prototype.getIsVerbose = function () {
return this._isVerbose;
};
/**
* Whether to append messages to the log file or to reset it on open.
*
* @param {Boolean} shouldAppend
*/
// FileLogHandler.prototype.setAppendToFile = function (shouldAppend) {
// this._appendToFile = !!shouldAppend;
// };
/**
* Whether to append messages to the log file or to reset it on open.
*
* @return {Boolean}
*/
// FileLogHandler.prototype.getAppendToFile = function () {
// return this._appendToFile;
// };
/**
* The name of the log file.
*
* @param {String} fileName
*/
FileLogHandler.prototype.setFileName = function (fileName) {
this._fileName = fileName;
};
/**
* The name of the log file.
*
* @return {String} the file name
*/
FileLogHandler.prototype.getFileName = function () {
return this._fileName;
};
/**
* The path of the log file folder.
*
* @param {String} fileDirectory
*/
FileLogHandler.prototype.setFileDirectory = function (fileDirectory) {
this._fileDirectory = fileDirectory;
};
/**
* The path of the log file folder.
*
* @return {String} the file Directory
*/
FileLogHandler.prototype.getFileDirectory = function () {
return this._fileDirectory;
};
FileLogHandler.prototype.open = function () {
this.close();
this._logger = new (winston.Logger)({
exitOnError: false,
transports: [
new (winston.transports.File)({
filename: this._fileName,
dirname: this._fileDirectory,
timestamp: timeStringFn,
json: false
})
]
});
};
FileLogHandler.prototype.close = function () {
if (this._logger) {
this._logger.close();
this._logger = undefined;
}
};
/**
* Write a message
* @param {Boolean} verbose - is the message verbose
* @param {String} message
*/
FileLogHandler.prototype.onMessage = function (verbose, message) {
if (!verbose || this._isVerbose) {
this._logger.info("Eyes: " + message);
}
};
module.exports = FileLogHandler;
}());