-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.17 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
var debugModule = require("debug");
var path = require("path");
var applicationName = "";
var applicationRootPath;
var addPid = true;
if (process.env.APP_ROOT) {
applicationRootPath = process.env.APP_ROOT;
}
else {
applicationRootPath = process.cwd();
}
if (process.env.APP_NAME) {
applicationName = process.env.APP_NAME;
}
else {
applicationName = path.basename(applicationRootPath);
}
if (process.env.DEBUG_PID) {
var dpid = process.env.DEBUG_PID.toLowerCase();
if (dpid === "yes" || dpid === "true" || dpid === "y") {
addPid = true;
}
else {
addPid = false;
}
}
exports = module.exports = function getDebug(namespace) {
var relativePath = path.relative(applicationRootPath, namespace);
var extname = path.extname(relativePath);
var identifier = path.basename(relativePath, extname);
var debugParts = path.dirname(relativePath).split(path.sep);
debugParts.push(identifier);
var relativeIdentifier = debugParts.join(":");
var processIdString = "";
if (addPid) {
processIdString = "(" + process.pid + ")";
}
return debugModule(applicationName + processIdString + ":" + relativeIdentifier);
}