forked from zhuyingda/webster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (51 loc) · 1.6 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
/**
* Copyright (c) 2017 5u9ar (zhuyingda)
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const log4js = require('log4js');
const path = require('path');
let configOption = {
appenders: {
webster: {}
},
categories: {
default: {
appenders: ['webster']
}
}
};
if (!!process.env.MOD) {
configOption.appenders.webster = {
type: 'stdout'
};
if (process.env.MOD === 'browser') {
configOption.categories.default.level = 'trace';
}
else {
configOption.categories.default.level = process.env.MOD;
}
}
else {
let curFile = require.main.filename.split('/');
curFile = curFile[curFile.length - 1];
if (/\.js$/.test(curFile)) {
curFile = curFile.replace(/\.js$/, '')
}
configOption.appenders.webster = {
type: 'file',
filename: path.resolve(process.env.HOME, `.webster/${curFile}.log`)
};
configOption.categories.default.level = 'info';
}
log4js.configure(configOption);
module.exports = require('./lib/Webster');