FIXED:
* More clear docs for bitmask
* Resolved potential issue for using PriorityAll in
  logging.logPrio.HasFlag.
This commit is contained in:
brent saner
2025-08-27 19:06:17 -04:00
parent 688abd0874
commit 2222cea7fb
7 changed files with 136 additions and 15 deletions

View File

@@ -4,6 +4,8 @@
-- no native Go support (yet)?
--- https://developer.apple.com/forums/thread/773369
- The log destinations for e.g. consts_nix.go et. al. probably should be unexported types.
- add a `log/slog` logging.Logger?
- Implement code line/func/etc. (only for debug?):

View File

@@ -23,8 +23,8 @@ const (
// LogUndefined indicates an undefined Logger type.
const LogUndefined bitmask.MaskBit = iota
const (
// LogJournald flags a SystemDLogger Logger type.
LogJournald = 1 << iota
// LogJournald flags a SystemDLogger Logger type. This will, for hopefully obvious reasons, only work on Linux systemd systems.
LogJournald bitmask.MaskBit = 1 << iota
// LogSyslog flags a SyslogLogger Logger type.
LogSyslog
// LogFile flags a FileLogger Logger type.

View File

@@ -3,16 +3,14 @@ package logging
import (
`os`
`path/filepath`
`r00t2.io/goutils/bitmask`
)
// Flags for logger configuration. These are used internally.
// LogUndefined indicates an undefined Logger type.
LogUndefined bitmask.MaskBit = 0
const (
// LogUndefined indicates an undefined Logger type.
LogUndefined bitmask.MaskBit = 1 << iota
// LogWinLogger indicates a WinLogger Logger type (Event Log).
LogWinLogger
LogWinLogger bitmask.MaskBit= 1 << iota
// LogFile flags a FileLogger Logger type.
LogFile
// LogStdout flags a StdLogger Logger type.

View File

@@ -17,7 +17,9 @@ func (l *logPrio) HasFlag(prio logPrio) (hasFlag bool) {
m = bitmask.NewMaskBitExplicit(uint(*l))
p = bitmask.NewMaskBitExplicit(uint(prio))
hasFlag = m.HasFlag(*p)
// Use IsOneOf instead in case PriorityAll is passed for prio.
// hasFlag = m.HasFlag(*p)
hasFlag = m.IsOneOf(*p)
return
}

View File

@@ -40,6 +40,8 @@ func (l *logWriter) Write(b []byte) (n int, err error) {
s = string(b)
// Since this explicitly checks each priority level, there's no need for IsOneOf in case of PriorityAll.
if l.prio.HasFlag(PriorityEmergency) {
if err = l.backend.Emerg(s); err != nil {
mErr.AddError(err)