Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case(syslog): added a case #64326

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/log/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ func New(priority Priority, tag string) (*Writer, error) {
// Otherwise, see the documentation for net.Dial for valid values
// of network and raddr.
func Dial(network, raddr string, priority Priority, tag string) (*Writer, error) {
w, err := newWriter(network, raddr, priority, tag)
if err != nil {
return nil, err
}

w.mu.Lock()
defer w.mu.Unlock()

err = w.connect()
if err != nil {
return nil, err
}
return w, err
}

func newWriter(network, raddr string, priority Priority, tag string) (*Writer, error) {
if priority < 0 || priority > LOG_LOCAL7|LOG_DEBUG {
return nil, errors.New("log/syslog: invalid priority")
}
Expand All @@ -125,22 +141,26 @@ func Dial(network, raddr string, priority Priority, tag string) (*Writer, error)
}
hostname, _ := os.Hostname()

w := &Writer{
return &Writer{
priority: priority,
tag: tag,
hostname: hostname,
network: network,
raddr: raddr,
}

w.mu.Lock()
defer w.mu.Unlock()
}, nil
}

err := w.connect()
func Open(network, raddr string, priority Priority, tag string) (*Writer, error) {
w, err := newWriter(network, raddr, priority, tag)
if err != nil {
return nil, err
}
return w, err

return w, nil
}

func (w *Writer) Ping() error {
return w.Info("ping")
}

// connect makes a connection to the syslog server.
Expand Down