Unverified Kaydet (Commit) b332cd74 authored tarafından Ali GOREN's avatar Ali GOREN Kaydeden (comit) GitHub

Merge pull request #4 from aligoren/dev

setFormat added, the send method moved from the logger to log server. colors array changes as an enum. colors file have NodeColors enum for node runtime now
...@@ -3,43 +3,52 @@ ...@@ -3,43 +3,52 @@
/** /**
* This colors only works on Node Runtime * This colors only works on Node Runtime
*/ */
const nodeColors = {
Reset : "\x1b[0m", enum NodeColors {
Bright : "\x1b[1m", Reset = "\x1b[0m",
Dim : "\x1b[2m", Bright = "\x1b[1m",
Underscore : "\x1b[4m", Dim = "\x1b[2m",
Blink : "\x1b[5m", Underscore = "\x1b[4m",
Reverse : "\x1b[7m", Blink = "\x1b[5m",
Hidden : "\x1b[8m", Reverse = "\x1b[7m",
Hidden = "\x1b[8m",
FgBlack : "\x1b[30m",
FgRed : "\x1b[31m", FgBlack = "\x1b[30m",
FgGreen : "\x1b[32m", FgRed = "\x1b[31m",
FgYellow : "\x1b[33m", FgGreen = "\x1b[32m",
FgBlue : "\x1b[34m", FgYellow = "\x1b[33m",
FgMagenta : "\x1b[35m", FgBlue = "\x1b[34m",
FgCyan : "\x1b[36m", FgMagenta = "\x1b[35m",
FgWhite : "\x1b[37m", FgCyan = "\x1b[36m",
FgWhite = "\x1b[37m",
BgBlack : "\x1b[40m",
BgRed : "\x1b[41m", BgBlack = "\x1b[40m",
BgGreen : "\x1b[42m", BgRed = "\x1b[41m",
BgYellow : "\x1b[43m", BgGreen = "\x1b[42m",
BgBlue : "\x1b[44m", BgYellow = "\x1b[43m",
BgMagenta : "\x1b[45m", BgBlue = "\x1b[44m",
BgCyan : "\x1b[46m", BgMagenta = "\x1b[45m",
BgWhite : "\x1b[47m", BgCyan = "\x1b[46m",
BgWhite = "\x1b[47m",
} }
class Colors { class Colors {
/**
* Static and readonly field. Shouldn't re-assign value.
* This field works when you're working on Node runtime.
*/
public static readonly Node = NodeColors
/** /**
* *
* @param type - Type web or node * @param type - Type web or node
* @deprecated Instead of this you should use Colors.TYPE_NAME
* @example Colors.Node.BgWhite
*/ */
static GET(type: string) { static GET(type: string) {
if (type == "node") { if (type == "node") {
return nodeColors return NodeColors
} else { } else {
} }
......
...@@ -59,11 +59,22 @@ class LogServer { ...@@ -59,11 +59,22 @@ class LogServer {
* @function sendToLogServer * @function sendToLogServer
* @param sendBody * @param sendBody
*/ */
public sendToLogServer(sendBody?: any) { private sendToLogServer(sendBody?: any) {
if (this.settings.useServer) { if (this.settings.useServer) {
this.sendToServer(sendBody) this.sendToServer(sendBody)
} }
} }
/**
* @description Send extra fields to the log backend
* @function send
* @param sendBody - Extra body field
* @example
* loggerInstance.send({ pageUrl: 'test', 'time': '12:30' })
*/
send(sendBody?: any) {
return this.sendToLogServer(sendBody)
}
} }
export default LogServer export default LogServer
\ No newline at end of file
...@@ -8,6 +8,9 @@ import Colors from './Colors' ...@@ -8,6 +8,9 @@ import Colors from './Colors'
*/ */
class Logger { class Logger {
private isFormatted: boolean
private formattedString: string
private config: any = { private config: any = {
useServer: false, useServer: false,
endPoint: '', endPoint: '',
...@@ -22,17 +25,11 @@ class Logger { ...@@ -22,17 +25,11 @@ class Logger {
this.config = logConfig this.config = logConfig
this.server = new LogServer(this.config.server) this.server = new LogServer(this.config.server)
} }
/** public setFormat(formatStr: string) {
* @description Send extra fields to the log backend this.isFormatted = true
* @function send
* @param sendBody - Extra body field
* @example
* loggerInstance.send({ pageUrl: 'test', 'time': '12:30' })
*/
public send(sendBody?: any) {
return this.server.sendToLogServer(sendBody)
} }
/** /**
...@@ -46,7 +43,8 @@ class Logger { ...@@ -46,7 +43,8 @@ class Logger {
debug(message: string, context: any) { debug(message: string, context: any) {
const logCode = LogTypes.DEBUG const logCode = LogTypes.DEBUG
const levelName = Levels.GET(logCode) const levelName = Levels.GET(logCode)
const colors = Colors.GET('node') const colors = Colors.Node //Colors.GET('node')
/** /**
* @todo This section will change. This needs formatted output * @todo This section will change. This needs formatted output
......
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