
ADD: * `iox` subpackage FIX: * `logging` now has a way to return logWritier directly * added significant `io.*` interface compat to logWriter -- allowing a `logging.Logger` to essentially be used for a large amount of io interaction in other libraries.
48 lines
924 B
Go
48 lines
924 B
Go
package logging
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
/*
|
|
ToLog returns a stdlib *log.Logger from a logging.Logger. It simply wraps the (logging.Logger).ToLogger() methods.
|
|
|
|
prio is an OR'd logPrio of the Priority* constants.
|
|
*/
|
|
func ToLog(l Logger, prio logPrio) (stdLibLog *log.Logger) {
|
|
|
|
stdLibLog = l.ToLogger(prio)
|
|
|
|
return
|
|
}
|
|
|
|
// ToRaw returns a *logWriter from a logging.Logger. It is an alternative to the (logging.Logger).ToRaw() methods.
|
|
func ToRaw(l Logger, prio logPrio) (raw *logWriter) {
|
|
|
|
raw = &logWriter{
|
|
backend: l,
|
|
prio: prio,
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// testOpen attempts to open a file for writing to test for suitability as a LogFile path.
|
|
func testOpen(path string) (success bool, err error) {
|
|
|
|
var f *os.File
|
|
|
|
// Example #2, https://golang.org/pkg/os/#OpenFile
|
|
if f, err = os.OpenFile(path, appendFlags, logPerm); err != nil {
|
|
return
|
|
}
|
|
if err = f.Close(); err != nil {
|
|
return
|
|
}
|
|
|
|
success = true
|
|
|
|
return
|
|
}
|