finalizing logging and multierror

This commit is contained in:
2022-01-05 05:15:38 -05:00
parent 3975f8b11f
commit 0e01306637
24 changed files with 1057 additions and 60 deletions

View File

@@ -6,6 +6,7 @@ import (
`path`
sysd `github.com/coreos/go-systemd/journal`
`r00t2.io/goutils/bitmask`
`r00t2.io/sysutils/paths`
)
@@ -17,16 +18,24 @@ var (
/*
GetLogger returns an instance of Logger that best suits your system's capabilities.
If enableDebug is true, debug messages (which according to your program may or may not contain sensitive data) are rendered and written.
If prefix is "\x00" (a null byte), then the default logging prefix will be used. If anything else, even an empty string,
is specified then that will be used instead for the prefix.
logPaths is an (optional) list of strings to use as paths to test for writing. If the file can be created/written to,
it will be used (assuming you have no higher-level loggers available). Only the first logPaths entry that "works" will be used, later entries will be ignored.
If you want to log to multiple files simultaneously, use a MultiLogger instead.
If you call GetLogger, you will only get a single ("best") logger your system supports.
If you want to log to multiple Logger destinations at once (or want to log to an explicit Logger type),
use GetMultiLogger.
*/
func GetLogger(enableDebug bool, prefix string, logPaths ...string) (logger Logger, err error) {
var logPath string
var logFlags types.MaskBit
var logFlags bitmask.MaskBit
// Configure system-supported logger(s).
if sysd.Enabled() {
@@ -67,7 +76,7 @@ func GetLogger(enableDebug bool, prefix string, logPaths ...string) (logger Logg
break
} else {
dirPath := path.Dir(p)
if err = paths.MakeDirIfNotExist(&dirPath); err != nil {
if err = paths.MakeDirIfNotExist(dirPath); err != nil {
continue
}
if success, err = testOpen(p); err != nil {