Skip to content

Commit

Permalink
Fix #11 , thanks to @blueyestar
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-dimitru committed Jan 2, 2018
1 parent e45c084 commit 6f97a4e
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,67 +41,67 @@ class LoggerFile {

return `${date}-${month}-${year}.log`;
};
}

/* format - Log record format */
if (this.options.format) {
if(!_.isFunction(this.options.format)) {
throw new Meteor.Error('[LoggerFile] [options.format] Must be a Function!');
}
} else {
this.options.format = (time, level, message, data, userId) => {
let month = `${time.getMonth() + 1}`;
if (month.length === 1) {
month = '0' + month;
}
let date = `${time.getDate()}`;
if (date.length === 1) {
date = '0' + date;
}
let year = `${time.getFullYear()}`;
if (year.length === 1) {
year = '0' + year;
}
let hours = `${time.getHours()}`;
if (hours.length === 1) {
hours = '0' + hours;
}
let mins = `${time.getMinutes()}`;
if (mins.length === 1) {
mins = '0' + mins;
}
let sec = `${time.getSeconds()}`;
if (sec.length === 1) {
sec = '0' + sec;
}

return `${date}-${month}-${year} ${hours}:${mins}:${sec} | [${level}] | Message: \"${message}\" | User: ${userId} | data: ${data}\r\n`;
};
/* format - Log record format */
if (this.options.format) {
if(!_.isFunction(this.options.format)) {
throw new Meteor.Error('[LoggerFile] [options.format] Must be a Function!');
}

/* path - Log's storage path */
if (this.options.path) {
if (!_.isString(this.options.path)) {
throw new Meteor.Error('[LoggerFile] [options.path] Must be a String!');
} else {
this.options.format = (time, level, message, data, userId) => {
let month = `${time.getMonth() + 1}`;
if (month.length === 1) {
month = '0' + month;
}
let date = `${time.getDate()}`;
if (date.length === 1) {
date = '0' + date;
}
let year = `${time.getFullYear()}`;
if (year.length === 1) {
year = '0' + year;
}
} else {
this.options.path = Meteor.rootPath + ((process.env.NODE_ENV === 'development') ? '/static/logs' : '/assets/app/logs');
let hours = `${time.getHours()}`;
if (hours.length === 1) {
hours = '0' + hours;
}
let mins = `${time.getMinutes()}`;
if (mins.length === 1) {
mins = '0' + mins;
}
let sec = `${time.getSeconds()}`;
if (sec.length === 1) {
sec = '0' + sec;
}

return `${date}-${month}-${year} ${hours}:${mins}:${sec} | [${level}] | Message: \"${message}\" | User: ${userId} | data: ${data}\r\n`;
};
}

/* path - Log's storage path */
if (this.options.path) {
if (!_.isString(this.options.path)) {
throw new Meteor.Error('[LoggerFile] [options.path] Must be a String!');
}
} else {
this.options.path = Meteor.rootPath + ((process.env.NODE_ENV === 'development') ? '/static/logs' : '/assets/app/logs');
}

this.options.path = this.options.path.replace(/\/$/, '');
this.options.path = this.options.path.replace(/\/$/, '');

fs.ensureDir(`${this.options.path}`, (EDError) => {
if (EDError) {
throw new Meteor.Error('[LoggerFile] [options.path] Error:', EDError);
}
fs.ensureDir(`${this.options.path}`, (EDError) => {
if (EDError) {
throw new Meteor.Error('[LoggerFile] [options.path] Error:', EDError);
}

fs.writeFile(`${this.options.path}/test`, 'test', (WFError) => {
if (WFError) {
throw new Meteor.Error(`[LoggerFile] [options.path] ${this.options.path} is not writable!!!`, WFError);
}
fs.unlink(`${this.options.path}/test`, NOOP);
});
fs.writeFile(`${this.options.path}/test`, 'test', (WFError) => {
if (WFError) {
throw new Meteor.Error(`[LoggerFile] [options.path] ${this.options.path} is not writable!!!`, WFError);
}
fs.unlink(`${this.options.path}/test`, NOOP);
});
}
});

this.logger.add('File', (level, message, data = null, userId) => {
const time = new Date();
Expand Down

0 comments on commit 6f97a4e

Please sign in to comment.