Browse Source

Fix shutdown function for console backend and eventlog backend.

ZRY 10 months ago
parent
commit
81287b7b18
2 changed files with 15 additions and 0 deletions
  1. 12 0
      hiedabke_console/hiedabke_console.go
  2. 3 0
      hiedabke_win_eventlog/win_eventlog.go

+ 12 - 0
hiedabke_console/hiedabke_console.go

@@ -13,6 +13,7 @@ type ConsoleBackend struct {
 	s_fc_json_key func(string) string
 	s_fc_json_val func(string) string
 	s_lvd         []func(string) string
+	enable        bool
 }
 
 func NewConsoleBackend(wr io.Writer) *ConsoleBackend {
@@ -29,11 +30,19 @@ func NewConsoleBackend(wr io.Writer) *ConsoleBackend {
 			chalk.Cyan.NewStyle().Style,
 			chalk.Blue.NewStyle().Style,
 		},
+		enable: true,
 	}
 	return scb
 }
 
+func (b *ConsoleBackend) Shutdown() {
+	b.enable = false
+}
+
 func (b *ConsoleBackend) EmitStringLog(module string, level hiedalog.HiedaLogLevel, content string) {
+	if !b.enable {
+		return
+	}
 	var lv string
 	if level.LevelNumber < 7 {
 		lv = b.s_lvd[level.LevelNumber](level.Name)
@@ -44,6 +53,9 @@ func (b *ConsoleBackend) EmitStringLog(module string, level hiedalog.HiedaLogLev
 }
 
 func (b *ConsoleBackend) EmitComplexLog(module string, level hiedalog.HiedaLogLevel, data map[string]string) {
+	if !b.enable {
+		return
+	}
 	b.EmitStringLog(module, level, b.prettyComplexToString(data))
 }
 

+ 3 - 0
hiedabke_win_eventlog/win_eventlog.go

@@ -54,6 +54,9 @@ func (b *WinEventLogBackend) EmitStringLog(module string, level hiedalog.HiedaLo
 }
 
 func (b *WinEventLogBackend) EmitComplexLog(module string, level hiedalog.HiedaLogLevel, data map[string]string) {
+	if !b.enable {
+		return
+	}
 	b.EmitStringLog(module, level, b.prettyComplexToString(data))
 }