updating to have func to print prefix

This commit is contained in:
brent s. 2021-02-27 00:51:58 -05:00
parent c6d53a0cca
commit 80985d1084
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
6 changed files with 59 additions and 44 deletions

View File

@ -1,14 +1,14 @@
package logging

import (
native `log`
`os`
`path`
native "log"
"os"
"path"

"r00t2.io/goutils/types"

sysd `github.com/coreos/go-systemd/journal`
`r00t2.io/sysutils/paths`
sysd "github.com/coreos/go-systemd/journal"
"r00t2.io/sysutils/paths"
)

var (
@ -39,9 +39,13 @@ func GetLogger(enableDebug bool, prefix string, logpaths ...string) (logger Logg
var stat os.FileInfo
var devlogPath string = devlog

if hasSyslog, stat, err = paths.RealPathExistsStat(&devlogPath); hasSyslog && err != nil {return}
if hasSyslog, stat, err = paths.RealPathExistsStat(&devlogPath); hasSyslog && err != nil {
return
}

if hasSyslog && !stat.Mode().IsRegular() {logflags.AddFlag(LogSyslog)} else {
if hasSyslog && !stat.Mode().IsRegular() {
logflags.AddFlag(LogSyslog)
} else {
var exists bool
var success bool
var ckLogPaths []string
@ -112,7 +116,7 @@ func GetLogger(enableDebug bool, prefix string, logpaths ...string) (logger Logg
logger.setPrefix(prefix)
}

logger.Info("logger initialized of type %T with prefix %v", logger, logger.Prefix)
logger.Info("logger initialized of type %T with prefix %v", logger, logger.GetPrefix())

return
}

View File

@ -1,10 +1,10 @@
package logging

import (
`fmt`
`io`
`log`
`os`
"fmt"
"io"
"log"
"os"
)

func (l *FileLogger) Setup() {
@ -31,6 +31,10 @@ func (l *FileLogger) Shutdown() {

}

func (l *FileLogger) GetPrefix() string {
return l.Prefix
}

func (l *FileLogger) doDebug(d bool) {
l.EnableDebug = d
}
@ -91,7 +95,6 @@ func (l *FileLogger) Debug(s string, v ...interface{}) (err error) {

func (l *FileLogger) Emerg(s string, v ...interface{}) (err error) {


var msg string

if v != nil {
@ -152,7 +155,6 @@ func (l *FileLogger) Notice(s string, v ...interface{}) (err error) {

func (l *FileLogger) Warning(s string, v ...interface{}) (err error) {


var msg string

if v != nil {

View File

@ -1,8 +1,8 @@
package logging

import (
`fmt`
`log`
"fmt"
"log"
)

func (l *StdLogger) Setup() {
@ -27,6 +27,10 @@ func (l *StdLogger) setPrefix(prefix string) {
l.Logger.SetPrefix(prefix)
}

func (l *StdLogger) GetPrefix() string {
return l.Prefix
}

func (l *StdLogger) Alert(s string, v ...interface{}) (err error) {

var msg string
@ -78,7 +82,6 @@ func (l *StdLogger) Debug(s string, v ...interface{}) (err error) {

func (l *StdLogger) Emerg(s string, v ...interface{}) (err error) {


var msg string

if v != nil {
@ -139,7 +142,6 @@ func (l *StdLogger) Notice(s string, v ...interface{}) (err error) {

func (l *StdLogger) Warning(s string, v ...interface{}) (err error) {


var msg string

if v != nil {

View File

@ -1,10 +1,10 @@
package logging

import (
`fmt`
`log`
"fmt"
"log"

`github.com/coreos/go-systemd/journal`
"github.com/coreos/go-systemd/journal"
)

func (l *SystemDLogger) Setup() {
@ -29,6 +29,10 @@ func (l *SystemDLogger) setPrefix(prefix string) {
l.Prefix = prefix
}

func (l *SystemDLogger) GetPrefix() string {
return l.Prefix
}

func (l *SystemDLogger) Alert(s string, v ...interface{}) (err error) {

var msg string
@ -80,7 +84,6 @@ func (l *SystemDLogger) Debug(s string, v ...interface{}) (err error) {

func (l *SystemDLogger) Emerg(s string, v ...interface{}) (err error) {


var msg string

if v != nil {
@ -141,7 +144,6 @@ func (l *SystemDLogger) Notice(s string, v ...interface{}) (err error) {

func (l *SystemDLogger) Warning(s string, v ...interface{}) (err error) {


var msg string

if v != nil {

View File

@ -1,9 +1,9 @@
package logging

import (
`fmt`
`log`
`log/syslog`
"fmt"
"log"
"log/syslog"
)

func (l *SyslogLogger) Setup() {
@ -58,6 +58,10 @@ func (l *SyslogLogger) setPrefix(prefix string) {
l.Setup()
}

func (l *SyslogLogger) GetPrefix() string {
return l.Prefix
}

func (l *SyslogLogger) Alert(s string, v ...interface{}) (err error) {

var msg string

View File

@ -1,9 +1,9 @@
package logging

import (
`log`
`log/syslog`
`os`
"log"
"log/syslog"
"os"
)

type Logger interface {
@ -17,6 +17,7 @@ type Logger interface {
Warning(string, ...interface{}) error
doDebug(bool)
setPrefix(string)
GetPrefix() string
Setup()
Shutdown()
}