move syslog into logger

This commit is contained in:
aler9 2021-03-25 20:30:36 +01:00
parent 10bf7bad43
commit c10faac9e5
4 changed files with 15 additions and 21 deletions

View File

@ -6,8 +6,6 @@ import (
"os"
"sync"
"time"
"github.com/aler9/rtsp-simple-server/internal/syslog"
)
// Level is a log level.
@ -63,7 +61,7 @@ func New(level Level, destinations map[Destination]struct{}, filePath string) (*
if _, ok := destinations[DestinationSyslog]; ok {
var err error
lh.syslog, err = syslog.New("rtsp-simple-server")
lh.syslog, err = newSyslog("rtsp-simple-server")
if err != nil {
lh.Close()
return nil, err

View File

@ -1,6 +1,6 @@
// +build !windows
package syslog
package logger
import (
"io"
@ -11,8 +11,7 @@ type syslog struct {
inner *native.Writer
}
// New allocates a io.WriteCloser that writes to the system log.
func New(prefix string) (io.WriteCloser, error) {
func newSyslog(prefix string) (io.WriteCloser, error) {
inner, err := native.New(native.LOG_INFO|native.LOG_DAEMON, prefix)
if err != nil {
return nil, err
@ -23,12 +22,10 @@ func New(prefix string) (io.WriteCloser, error) {
}, nil
}
// Close implements io.WriteCloser.
func (ls *syslog) Close() error {
return ls.inner.Close()
}
// Write implements io.WriteCloser.
func (ls *syslog) Write(p []byte) (int, error) {
return ls.inner.Write(p)
}

View File

@ -0,0 +1,12 @@
// +build windows
package logger
import (
"fmt"
"io"
)
func newSyslog(prefix string) (io.WriteCloser, error) {
return nil, fmt.Errorf("not implemented on windows")
}

View File

@ -1,13 +0,0 @@
// +build windows
package syslog
import (
"fmt"
"io"
)
// New allocates a io.WriteCloser that writes to the system log.
func New(prefix string) (io.WriteCloser, error) {
return nil, fmt.Errorf("not implemented on windows")
}