forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add logging for UI gekkos, fix askmike#972
- Loading branch information
Showing
5 changed files
with
57 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
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,40 @@ | ||
const fs = require('fs'); | ||
const moment = require('moment'); | ||
const _ = require('lodash'); | ||
|
||
const BASEPATH = __dirname + '/../../logs/'; | ||
|
||
const Logger = function(type) { | ||
|
||
const now = moment().utc().format('YYYY-MM-DD-HH-mm'); | ||
this.fileName = `${now}-UTC-${type}.log`; | ||
|
||
this.writing = false; | ||
this.queue = []; | ||
|
||
_.bindAll(this); | ||
} | ||
|
||
Logger.prototype.write = function(line) { | ||
if(!this.writing) { | ||
this.writing = true; | ||
fs.appendFile( | ||
BASEPATH + this.fileName, | ||
line + '\n', | ||
this.handleWriteCallback | ||
); | ||
} else | ||
this.queue.push(line); | ||
} | ||
|
||
Logger.prototype.handleWriteCallback = function(err) { | ||
if(err) | ||
console.error(`ERROR WRITING LOG FILE ${this.fileName}:`, err); | ||
|
||
this.writing = false; | ||
|
||
if(_.size(this.queue)) | ||
this.write(this.queue.shift()) | ||
} | ||
|
||
module.exports = Logger; |