diff --git a/log.go b/log.go index 1890784..c7bb3fc 100644 --- a/log.go +++ b/log.go @@ -1,3 +1,5 @@ +//go:build !avr + package csp import ( @@ -9,14 +11,16 @@ import ( var Logger io.Writer = nil func log(format string, args ...interface{}) { - if Logger != nil { - Logger.Write([]byte(fmt.Sprintf(format, args...))) + if Logger == nil { + return } + Logger.Write([]byte(fmt.Sprintf(format, args...))) } func logTs(format string, args ...interface{}) { - if Logger != nil { - args = append([]interface{}{time.Now().Format("15:04:05.000")}, args...) - Logger.Write([]byte(fmt.Sprintf("%s "+format, args...))) + if Logger == nil { + return } + args = append([]interface{}{time.Now().Format("15:04:05.000")}, args...) + Logger.Write([]byte(fmt.Sprintf("%s "+format, args...))) } diff --git a/log_avr.go b/log_avr.go new file mode 100644 index 0000000..ade582c --- /dev/null +++ b/log_avr.go @@ -0,0 +1,24 @@ +//go:build avr + +package csp + +import ( + "io" +) + +var Logger io.Writer = nil + +func log(_ string, args ...interface{}) { + if Logger == nil { + return + } + for _, arg := range args { + if _, err := Logger.Write([]byte(arg.(string))); err != nil { + return + } + } +} + +func logTs(format string, args ...interface{}) { + log(format, args...) +}