Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 73 additions & 73 deletions logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ConfigReader from '../configReader/configReader.js';
import API_TYPE from '../enum/apiType.js';

export default class Logger {

constructor(level, caller){
this.logSetting = ConfigReader.instance.getConfig()[API_TYPE.LOGGER];
this.logFile = path.join(process.env.PWD, 'logs', 'mapi.log');
Expand Down Expand Up @@ -39,108 +39,108 @@ export default class Logger {
try {
let prefix = this.TAG;
prefix += `[${this.caller}]`
if(this.logSetting['time-log'] === 'yes')
{
if(this.logSetting['time-log'] === 'yes')
{
prefix += `(${new Date().toLocaleString()})`;
}
}
prefix += ': '

const outstream = `${prefix} ${msg}`
fs.appendFileSync(this.logFile, `${outstream}\r\n`, 'utf-8');
console.log(outstream);
}catch (e){
}catch (e){
console.error(e.stack || e);
console.error("Unknown error occured while logging msg::\n", msg);
}
}
}

debug(msg){
if(this.logSetting.level) {
switch(this.logSetting.level) {
case "error": case "warn": case "info":
return;
}
}

switch(this.level)
{
case "debug":
this.log(`[-DEBUG-] ${msg}`);
break;
}
switch(this.logSetting.level) {
case "error": case "warn": case "info":
return;
}
}

switch(this.level)
{
case "debug":
this.log(`[-DEBUG-] ${msg}`);
break;
}
}

info(msg){
if(this.logSetting.level) {
switch(this.logSetting.level) {
case "error": case "warn":
return;
}
}

switch(this.level)
{
case "info": case "debug":
this.log(msg);
break;
}
switch(this.logSetting.level) {
case "error": case "warn":
return;
}
}

switch(this.level)
{
case "info": case "debug":
this.log(msg);
break;
}
}

warn(msg){
if(this.logSetting.level) {
switch(this.logSetting.level) {
case "error":
return;
}
}

switch(this.level)
{
case "info": case "warn": case "debug":
this.log(`[*WARN*] ${msg}`);
break;
}
switch(this.logSetting.level) {
case "error":
return;
}
}

switch(this.level)
{
case "info": case "warn": case "debug":
this.log(`[*WARN*] ${msg}`);
break;
}
}

error(msg){
switch(this.level)
{
case "info": case "warn": case "error": case "debug":
this.log(`[**ERROR**] ${msg}`);
break;
}
{
case "info": case "warn": case "error": case "debug":
this.log(`[**ERROR**] ${msg}`);
break;
}
}

temp(msg, doFlush){
if(this.tempMessage != null) {
if(doFlush)
{
warn(" --AUTO FLUSHING--: " + this.tempMessage);
this.tempMessage = null;
return;
}

if(msg != null)
this.tempMessage += "\n" + msg;
}else {
if(msg != null)
this.tempMessage = msg;
}
if(doFlush)
{
warn(" --AUTO FLUSHING--: " + this.tempMessage);
this.tempMessage = null;
return;
}

if(msg != null)
this.tempMessage += "\n" + msg;
}else {
if(msg != null)
this.tempMessage = msg;
}
}

flush(msgType){
if(this.tempMessage != null)
{
if(msgType == "info")
this.info(this.tempMessage);
else if(msgType == "warn")
this.warn(this.tempMessage);
else if(msgType == "error")
this.error(this.tempMessage);
else if(msgType == "debug")
this.debug(this.tempMessage);

this.tempMessage = null;
}
{
if(msgType == "info")
this.info(this.tempMessage);
else if(msgType == "warn")
this.warn(this.tempMessage);
else if(msgType == "error")
this.error(this.tempMessage);
else if(msgType == "debug")
this.debug(this.tempMessage);

this.tempMessage = null;
}
}
}
}