Browse Source

move syslog into logger

pull/340/head
aler9 5 years ago
parent
commit
c10faac9e5
  1. 4
      internal/logger/logger.go
  2. 7
      internal/logger/syslog_unix.go
  3. 12
      internal/logger/syslog_win.go
  4. 13
      internal/syslog/syslog_win.go

4
internal/logger/logger.go

@ -6,8 +6,6 @@ import ( @@ -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) (* @@ -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

7
internal/syslog/syslog_unix.go → internal/logger/syslog_unix.go

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// +build !windows
package syslog
package logger
import (
"io"
@ -11,8 +11,7 @@ type syslog struct { @@ -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) { @@ -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)
}

12
internal/logger/syslog_win.go

@ -0,0 +1,12 @@ @@ -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")
}

13
internal/syslog/syslog_win.go

@ -1,13 +0,0 @@ @@ -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")
}
Loading…
Cancel
Save