golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
640 B
35 lines
640 B
package logger |
|
|
|
import ( |
|
"bytes" |
|
"os" |
|
"time" |
|
) |
|
|
|
type destinationFile struct { |
|
file *os.File |
|
buf bytes.Buffer |
|
} |
|
|
|
func newDestinationFile(filePath string) (destination, error) { |
|
f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) |
|
if err != nil { |
|
return nil, err |
|
} |
|
|
|
return &destinationFile{ |
|
file: f, |
|
}, nil |
|
} |
|
|
|
func (d *destinationFile) log(t time.Time, level Level, format string, args ...interface{}) { |
|
d.buf.Reset() |
|
writeTime(&d.buf, t, false) |
|
writeLevel(&d.buf, level, false) |
|
writeContent(&d.buf, format, args) |
|
d.file.Write(d.buf.Bytes()) |
|
} |
|
|
|
func (d *destinationFile) close() { |
|
d.file.Close() |
|
}
|
|
|