Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit ef61403

Browse files
committed
Fix build for Windows
This PR fixes the package so it can be imported when used under Windows. The `syslog` package unfortunately is not supported under Windows. Hence we disable it if we detect it. Fixes the following error: ``` xlog.go:66:12: undefined: syslog.New xlog.go:66:23: undefined: syslog.LOG_DEBUG ```
1 parent 6f59da6 commit ef61403

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

xlog/syslog.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// +build linux darwin dragonfly freebsd netbsd openbsd solaris
2+
3+
package xlog
4+
5+
import "log/syslog"
6+
7+
// NewSysLog creates a new sys log.
8+
func NewSysLog(opts ...Option) *Log {
9+
w, err := syslog.New(syslog.LOG_DEBUG, "")
10+
if err != nil {
11+
panic(err)
12+
}
13+
return NewXLog(w, opts...)
14+
}

xlog/syslog_windows.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// +build windows
2+
3+
package xlog
4+
5+
import (
6+
"os"
7+
)
8+
9+
// NewSysLog creates a new sys log. Because there is no syslog support for
10+
// Windows, we output to os.Stdout.
11+
func NewSysLog(opts ...Option) *Log {
12+
return NewXLog(os.Stdout, opts...)
13+
}

xlog/xlog.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"fmt"
1414
"io"
1515
"log"
16-
"log/syslog"
1716
"os"
1817
"strings"
1918
)
@@ -61,15 +60,6 @@ type Log struct {
6160
*log.Logger
6261
}
6362

64-
// NewSysLog creates a new sys log.
65-
func NewSysLog(opts ...Option) *Log {
66-
w, err := syslog.New(syslog.LOG_DEBUG, "")
67-
if err != nil {
68-
panic(err)
69-
}
70-
return NewXLog(w, opts...)
71-
}
72-
7363
// NewStdLog creates a new std log.
7464
func NewStdLog(opts ...Option) *Log {
7565
return NewXLog(os.Stdout, opts...)

0 commit comments

Comments
 (0)