-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {fdopen} from 'fs'; | ||
import {traceback} from 'debug'; | ||
|
||
let tty; | ||
|
||
function _infos_from_stacktrace() { | ||
let st = traceback(4)[0]; | ||
let _fn = split(st.filename, '/'); | ||
return { | ||
filename: pop(_fn) | ||
}; | ||
} | ||
|
||
function _log(facility, ...args) { | ||
let info = _infos_from_stacktrace(); | ||
let msg = sprintf(...args); | ||
|
||
if (tty) { | ||
let t = localtime(); | ||
let time_str = sprintf('%02d:%02d:%02d', t.hour, t.min, t.sec); | ||
let fmt = '%s [%s] %s: %s\n'; | ||
printf(fmt, time_str, facility, info.filename, msg); | ||
|
||
} else { | ||
let fmt = '[%s] %s: %s'; | ||
printf(fmt, facility, info.filename, msg); | ||
} | ||
} | ||
|
||
function DBG(...args) { | ||
_log('Debug', ...args); | ||
} | ||
|
||
function INFO(...args) { | ||
_log('Info', ...args); | ||
} | ||
|
||
function WARN(...args) { | ||
_log('Warn', ...args); | ||
} | ||
|
||
function ERR(...args) { | ||
_log('Error', ...args); | ||
} | ||
|
||
tty = fdopen(0, 'r').isatty(); | ||
|
||
export { DBG, INFO, WARN, ERR }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters