Kaydet (Commit) 71879178 authored tarafından Ali's avatar Ali

Debug function changed. setMessage added, setFormat added and getDateWithTime…

Debug function changed. setMessage added, setFormat added and getDateWithTime added. Logger class now works with singleton pattern
üst dd89f5db
......@@ -11,13 +11,21 @@ class Logger {
private isFormatted: boolean
private formattedString: string
/**
* Singleton instance
*/
private instance: Logger
private config: any = {
platform: 'web',
server: {
useServer: false,
endPoint: '',
method: 'POST',
headers: {},
body: {}
}
}
private server: LogServer
......@@ -26,12 +34,42 @@ class Logger {
this.server = new LogServer(this.config.server)
if (!this.instance) {
this.instance = this
}
return this
}
/**
* @description This helps to get date with time
* @function getDateWithTime
* @example this.getDateWithTime() // output: 2019-05-16 12:03:48
*/
private getDateWithTime() {
const date = (new Date()).toISOString().split('T')[0]
const time = (new Date()).toISOString().split('T')[1].slice(0, 8)
return `${date} ${time}`
}
public setFormat(formatStr: string) {
this.isFormatted = true
}
private setMessage(details: any) {
const logDate = this.getDateWithTime()
let logString = `[${logDate}] - ${details.foregroundColor}${details.backgroundColor} ${details.levelName} ${details.reset} - `
logString += `${details.message}`
logString = logString.trim()
return logString
}
/**
* @description Debug Level Message
* @function debug
......@@ -43,14 +81,19 @@ class Logger {
debug(message: string, context: any) {
const logCode = LogTypes.DEBUG
const levelName = Levels.GET(logCode)
const colors = Colors.Node //Colors.GET('node')
const colors = this.config.platform == "web" ? Colors["Web"] : Colors["Node"]
const messageData = {
foregroundColor: colors.FgWhite,
backgroundColor: colors.BgRed,
levelName: levelName,
message: message,
reset: colors.Reset
}
const messageOutput = this.setMessage(messageData)
/**
* @todo This section will change. This needs formatted output
*/
console.log(logCode, levelName)
console.log(`${colors.FgWhite}${colors.BgRed}%s`, `${levelName}`, colors.Reset, '-', message);
console.log(messageOutput)
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment