mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-25 17:56:34 +08:00
Merge pull request #1596 from mholt/closinglogs
httpserver: Don't close stdout or stderr when closing logs (fix #1471)
This commit is contained in:
commit
ad4191a07e
|
@ -91,17 +91,14 @@ selectwriter:
|
||||||
switch l.Output {
|
switch l.Output {
|
||||||
case "", "stderr":
|
case "", "stderr":
|
||||||
l.writer = os.Stderr
|
l.writer = os.Stderr
|
||||||
|
|
||||||
case "stdout":
|
case "stdout":
|
||||||
l.writer = os.Stdout
|
l.writer = os.Stdout
|
||||||
|
|
||||||
case "syslog":
|
case "syslog":
|
||||||
l.writer, err = gsyslog.NewLogger(gsyslog.LOG_ERR, "LOCAL0", "caddy")
|
l.writer, err = gsyslog.NewLogger(gsyslog.LOG_ERR, "LOCAL0", "caddy")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if address := parseSyslogAddress(l.Output); address != nil {
|
if address := parseSyslogAddress(l.Output); address != nil {
|
||||||
l.writer, err = gsyslog.DialLogger(address.network, address.address, gsyslog.LOG_ERR, "LOCAL0", "caddy")
|
l.writer, err = gsyslog.DialLogger(address.network, address.address, gsyslog.LOG_ERR, "LOCAL0", "caddy")
|
||||||
|
|
||||||
|
@ -136,6 +133,11 @@ selectwriter:
|
||||||
|
|
||||||
// Close closes open log files or connections to syslog.
|
// Close closes open log files or connections to syslog.
|
||||||
func (l *Logger) Close() error {
|
func (l *Logger) Close() error {
|
||||||
|
// don't close stdout or stderr
|
||||||
|
if l.writer == os.Stdout || l.writer == os.Stderr {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Will close local/remote syslog connections too :)
|
// Will close local/remote syslog connections too :)
|
||||||
if closer, ok := l.writer.(io.WriteCloser); ok {
|
if closer, ok := l.writer.(io.WriteCloser); ok {
|
||||||
l.fileMu.Lock()
|
l.fileMu.Lock()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user