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