Skip to content

Commit

Permalink
Support AVR (can not have heavy "fmt" package)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysoldak committed Jul 8, 2024
1 parent 554e0c3 commit 1e0d116
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
14 changes: 9 additions & 5 deletions log.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !avr

package csp

import (
Expand All @@ -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...)))
}
24 changes: 24 additions & 0 deletions log_avr.go
Original file line number Diff line number Diff line change
@@ -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...)
}

0 comments on commit 1e0d116

Please sign in to comment.