mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #13810 from d23/syslog-facility
Add syslog-facility option
This commit is contained in:
commit
4dd1d1bfa5
2 changed files with 77 additions and 2 deletions
|
@ -3,12 +3,14 @@
|
|||
package syslog
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"log/syslog"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
@ -18,6 +20,29 @@ import (
|
|||
|
||||
const name = "syslog"
|
||||
|
||||
var facilities = map[string]syslog.Priority{
|
||||
"kern": syslog.LOG_KERN,
|
||||
"user": syslog.LOG_USER,
|
||||
"mail": syslog.LOG_MAIL,
|
||||
"daemon": syslog.LOG_DAEMON,
|
||||
"auth": syslog.LOG_AUTH,
|
||||
"syslog": syslog.LOG_SYSLOG,
|
||||
"lpr": syslog.LOG_LPR,
|
||||
"news": syslog.LOG_NEWS,
|
||||
"uucp": syslog.LOG_UUCP,
|
||||
"cron": syslog.LOG_CRON,
|
||||
"authpriv": syslog.LOG_AUTHPRIV,
|
||||
"ftp": syslog.LOG_FTP,
|
||||
"local0": syslog.LOG_LOCAL0,
|
||||
"local1": syslog.LOG_LOCAL1,
|
||||
"local2": syslog.LOG_LOCAL2,
|
||||
"local3": syslog.LOG_LOCAL3,
|
||||
"local4": syslog.LOG_LOCAL4,
|
||||
"local5": syslog.LOG_LOCAL5,
|
||||
"local6": syslog.LOG_LOCAL6,
|
||||
"local7": syslog.LOG_LOCAL7,
|
||||
}
|
||||
|
||||
type Syslog struct {
|
||||
writer *syslog.Writer
|
||||
}
|
||||
|
@ -39,10 +64,15 @@ func New(ctx logger.Context) (logger.Logger, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
facility, err := parseFacility(ctx.Config["syslog-facility"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log, err := syslog.Dial(
|
||||
proto,
|
||||
address,
|
||||
syslog.LOG_DAEMON,
|
||||
facility,
|
||||
path.Base(os.Args[0])+"/"+tag,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -102,3 +132,20 @@ func parseAddress(address string) (string, string, error) {
|
|||
|
||||
return "", "", nil
|
||||
}
|
||||
|
||||
func parseFacility(facility string) (syslog.Priority, error) {
|
||||
if facility == "" {
|
||||
return syslog.LOG_DAEMON, nil
|
||||
}
|
||||
|
||||
if syslogFacility, valid := facilities[facility]; valid {
|
||||
return syslogFacility, nil
|
||||
}
|
||||
|
||||
fInt, err := strconv.Atoi(facility)
|
||||
if err == nil && 0 <= fInt && fInt <= 23 {
|
||||
return syslog.Priority(fInt << 3), nil
|
||||
}
|
||||
|
||||
return syslog.Priority(0), errors.New("invalid syslog facility")
|
||||
}
|
||||
|
|
|
@ -891,6 +891,7 @@ The following logging options are supported for this logging driver:
|
|||
|
||||
--log-opt syslog-address=[tcp|udp]://host:port
|
||||
--log-opt syslog-address=unix://path
|
||||
--log-opt syslog-facility=daemon
|
||||
--log-opt syslog-tag="mailer"
|
||||
|
||||
`syslog-address` specifies the remote syslog server address where the driver connects to.
|
||||
|
@ -901,7 +902,34 @@ remote server at `192.168.0.42` on port `123`
|
|||
|
||||
$ docker run --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.42:123
|
||||
|
||||
`syslog-tag` specifies tag for syslog messages from container.
|
||||
The `syslog-facility` option configures the syslog facility. By default, the system uses the
|
||||
`daemon` value. To override this behavior, you can provide an integer of 0 to 23 or any of
|
||||
the following named facilities:
|
||||
|
||||
* `kern`
|
||||
* `user`
|
||||
* `mail`
|
||||
* `daemon`
|
||||
* `auth`
|
||||
* `syslog`
|
||||
* `lpr`
|
||||
* `news`
|
||||
* `uucp`
|
||||
* `cron`
|
||||
* `authpriv`
|
||||
* `ftp`
|
||||
* `local0`
|
||||
* `local1`
|
||||
* `local2`
|
||||
* `local3`
|
||||
* `local4`
|
||||
* `local5`
|
||||
* `local6`
|
||||
* `local7`
|
||||
|
||||
The `syslog-tag` specifies a tag that identifies the container's syslog messages. By default,
|
||||
the system uses the first 12 characters of the container id. To override this behavior, specify
|
||||
a `syslog-tag` option
|
||||
|
||||
#### Logging driver: journald
|
||||
|
||||
|
|
Loading…
Reference in a new issue