11var fs = require ( 'fs' ) ,
2- path = require ( 'path' ) ,
3- os = require ( 'os' ) ,
2+ path = require ( 'path' ) ,
3+ os = require ( 'os' ) ,
44 fileHelpers = require ( "./file_helpers" ) ( ) ;
55
6- module . exports = function ( setting ) {
7-
6+ module . exports = function ( setting ) {
87 var logDirectory = path . dirname ( setting . logPath ) ;
9- if ( ! fs . existsSync ( logDirectory ) ) {
10- console . error ( "couldn't find logDirectory so it will be created in place:" + setting . logPath ) ;
11- fileHelpers . ensureDirectories ( setting . logPath ) ;
12- }
13- if ( os . type ( ) . indexOf ( 'Windows' ) === - 1 ) {
14- var appLogStat = fs . statSync ( logDirectory ) ;
15- if ( canWrite ( process . uid === appLogStat . uid , process . gid === appLogStat . gid , appLogStat . mode ) ) {
16- console . error ( "ERROR WRITING TO LOG FILE DIRECTORY : " + logDirectory ) ;
17- process . exit ( - 1 ) ;
8+
9+ // TODO: Logging to file disabled temporarily, console output is default
10+
11+ // if (!fs.existsSync(logDirectory)) {
12+ // console.error("couldn't find logDirectory so it will be created in place:" + setting.logPath);
13+ // fileHelpers.ensureDirectories(setting.logPath);
14+ // }
15+ // if (os.type().indexOf('Windows') === -1) {
16+ // var appLogStat = fs.statSync(logDirectory);
17+ // if (canWrite(process.uid === appLogStat.uid, process.gid === appLogStat.gid, appLogStat.mode)) {
18+ // console.error("ERROR WRITING TO LOG FILE DIRECTORY : " + logDirectory);
19+ // process.exit(-1);
20+ // }
21+ // }
22+
23+ var appLog = createLog ( setting . APP_NAME , logDirectory , setting ) ;
24+
25+ if ( setting . disable ) {
26+ for ( var prop in appLog ) {
27+ appLog [ prop ] = function ( ) { } ;
1828 }
1929 }
2030
21- var appLog = createLog ( setting . APP_NAME , logDirectory , setting ) ;
22-
23- if ( setting . disable ) {
24- for ( var prop in appLog ) {
25- appLog [ prop ] = function ( ) { } ;
26- }
27- }
28- return appLog ;
31+ return appLog ;
2932} ;
3033
31- function canWrite ( owner , inGroup , mode ) {
34+ function canWrite ( owner , inGroup , mode ) {
3235 return owner && ( mode & 00200 ) || // User is owner and owner can write.
3336 inGroup && ( mode & 00020 ) || // User is in group and group can write.
3437 ( mode & 00002 ) ; // Anyone can write.
3538}
3639
37- function createLog ( appName , logDirectory , setting ) {
38-
39- var appLog = { } ;
40-
40+ function createLog ( appName , logDirectory , setting ) {
41+
42+ var appLog = { } ;
43+
4144 function getRequestId ( ) {
4245 return ( process . domain && process . domain . id ) || "" ;
4346 }
4447
45- function getLogDate ( ) {
48+ function getLogDate ( ) {
4649 var today = new Date ( ) ;
4750
4851 var fullYear = today . getFullYear ( ) ;
@@ -65,28 +68,25 @@ function createLog(appName, logDirectory, setting){
6568 var logFile = logDirectory + path . sep + appName + ".log" ;
6669 var augmentedLine = getLogDate ( ) + "\t" + line + os . EOL
6770 fs . appendFile ( logFile , augmentedLine , function ( err ) {
68- if ( err ) {
69- throw "couldn't write to " + logFile ;
71+ if ( err ) {
72+ throw "couldn't write to " + logFile ;
7073 }
7174 } ) ;
7275 }
73-
76+
7477 appLog . log = function ( input ) {
75- console . log ( setMessageWithFormat ( input ) ) ;
76- appendToLogFile ( input ) ;
77- }
78+ console . log ( setMessageWithFormat ( input ) ) ;
79+ }
7880
7981 appLog . info = appLog . log ;
80-
82+
8183 appLog . warn = function ( input ) {
82- console . warn ( setMessageWithFormat ( input ) ) ;
83- appendToLogFile ( input ) ;
84- }
85-
84+ console . warn ( setMessageWithFormat ( input ) ) ;
85+ }
86+
8687 appLog . error = function ( input ) {
87- console . error ( setMessageWithFormat ( input ) ) ;
88- appendToLogFile ( input ) ;
89- }
88+ console . error ( setMessageWithFormat ( input ) ) ;
89+ }
9090
9191 return appLog ;
9292}
0 commit comments