Skip to content

Commit

Permalink
v3.0.6 - Logging module
Browse files Browse the repository at this point in the history
  • Loading branch information
MickMake committed May 15, 2023
1 parent 23f00cf commit fc4bb2b
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 162 deletions.
34 changes: 10 additions & 24 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ Next up:
- Maybe add all known endpoints to mqtt as an option for regular polling instead of using a json file.


---
2023-05-15 21:22:24.895 ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on 'homeassistant/sensor/GoSungrow/GoSungrow-getPsDetail-1129147-p83072/state': '{"value":""}'
ValueError: could not convert string to float: ''
ValueError: Template error: float got invalid input '' when rendering template '{{ value_json.value | float }}' but no default was specified
2023-05-15 21:22:25.216 ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on 'homeassistant/sensor/GoSungrow/GoSungrow-virtual-1129147-p83097/state': '{"value":""}'
ValueError: could not convert string to float: ''
ValueError: Template error: float got invalid input '' when rendering template '{{ value_json.value | float }}' but no default was specified
2023-05-15 21:22:25.290 ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on 'homeassistant/sensor/GoSungrow/GoSungrow-getPsDetail-1129147-p83118/state': '{"value":""}'
ValueError: could not convert string to float: ''
ValueError: Template error: float got invalid input '' when rendering template '{{ value_json.value | float }}' but no default was specified
ValueError: could not convert string to float: 'unknown'


Formatting issues:
- getUpTimePoint <- map[string]
- AppService.getKpiInfo <- map[string]
Expand Down
116 changes: 116 additions & 0 deletions cmd/cmd_logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package cmd

import (
"fmt"
"github.com/MickMake/GoUnify/cmdLog"
"strings"
)


type Logging struct {
logLevel int
logger cmdLog.Log
}

// -------------------------------------------------------------------------------- //

const (
LogLevelDebug = 0
LogLevelInfo = iota
LogLevelWarning = iota
LogLevelError = iota

LogLevelDebugStr = "debug"
LogLevelInfoStr = "info"
LogLevelWarningStr = "warning"
LogLevelErrorStr = "error"
)

func NewLogging(level string) Logging {
ret := Logging{}
ret.SetLogLevel(level)
ret.logger = cmdLog.Log{}

return ret
}

func (c *Logging) SetLogLevel(level string) {
switch strings.ToLower(level) {
case LogLevelDebugStr:
c.logLevel = LogLevelDebug
case LogLevelInfoStr:
c.logLevel = LogLevelInfo
case LogLevelWarningStr:
c.logLevel = LogLevelWarning
case LogLevelErrorStr:
c.logLevel = LogLevelError
default:
cmdLog.LogPrintDate("Unknown log level, setting to default.")
c.logLevel = LogLevelInfo
}
}

func (c *Logging) GetLogLevel() string {
var ret string
switch c.logLevel {
case LogLevelDebug:
ret = LogLevelDebugStr
case LogLevelInfo:
ret = LogLevelInfoStr
case LogLevelWarning:
ret = LogLevelWarningStr
case LogLevelError:
ret = LogLevelErrorStr
default:
ret = LogLevelInfoStr
}
return ret
}

func (c *Logging) Debug(format string, args ...interface{}) {
if LogLevelDebug >= c.logLevel {
cmdLog.LogPrintDate("DEBUG: " + format, args...)
}
}

func (c *Logging) Info(format string, args ...interface{}) {
if LogLevelInfo >= c.logLevel {
cmdLog.LogPrintDate("INFO: " + format, args...)
}
}

func (c *Logging) Warning(format string, args ...interface{}) {
if LogLevelWarning >= c.logLevel {
cmdLog.LogPrintDate("WARNING: " + format, args...)
}
}

func (c *Logging) Error(format string, args ...interface{}) {
if LogLevelError >= c.logLevel {
cmdLog.LogPrintDate("ERROR: " + format, args...)
}
}

func (c *Logging) PlainDebug(format string, args ...interface{}) {
if LogLevelDebug >= c.logLevel {
fmt.Print(cmdLog.LogSprintf(format, args...))
}
}

func (c *Logging) PlainInfo(format string, args ...interface{}) {
if LogLevelInfo >= c.logLevel {
fmt.Print(cmdLog.LogSprintf(format, args...))
}
}

func (c *Logging) PlainWarning(format string, args ...interface{}) {
if LogLevelWarning >= c.logLevel {
fmt.Print(cmdLog.LogSprintf(format, args...))
}
}

func (c *Logging) PlainError(format string, args ...interface{}) {
if LogLevelError >= c.logLevel {
fmt.Print(cmdLog.LogSprintf(format, args...))
}
}

0 comments on commit fc4bb2b

Please sign in to comment.