Skip to content
Myr

feat: LogToFileWith (#692)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Allows to log to file with custom loggers, provided they implement SetOutput and SetPrefix.

authored by Carlos Alexandro Becker · committed by GitHub · parent de6740d · Browse files · 1 file+13 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−0 removed

  • other:+13 added−0 removed

1 file+13 added−0 removed

modified:logging.go+13 added
1package tea23import (4 "io"5 "log"6 "os"7 "unicode"8)
10 unmodified lines
19// os.Exit(1)20// }21// defer f.Close()22func LogToFile(path string, prefix string) (*os.File, error) {23 return LogToFileWith(path, prefix, log.Default())24}2526// LogOptionsSetter is an interface implemented by stdlib's log and charm's log27// libraries.28type LogOptionsSetter interface {29 SetOutput(io.Writer)30 SetPrefix(string)31}3233// LogToFileWith does allows to call LogToFile with a custom LogOptionsSetter.34func LogToFileWith(path string, prefix string, log LogOptionsSetter) (*os.File, error) {35 f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)36 if err != nil {37 return nil, err38 }
14 unmodified lines