mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Add syslog support for log and errors directives
This commit is contained in:
parent
ec51e14451
commit
4b92808bbf
2 changed files with 16 additions and 2 deletions
|
@ -2,11 +2,13 @@ package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-syslog"
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
"github.com/mholt/caddy/middleware/errors"
|
"github.com/mholt/caddy/middleware/errors"
|
||||||
)
|
)
|
||||||
|
@ -21,12 +23,17 @@ func Errors(c *Controller) (middleware.Middleware, error) {
|
||||||
// Open the log file for writing when the server starts
|
// Open the log file for writing when the server starts
|
||||||
c.Startup = append(c.Startup, func() error {
|
c.Startup = append(c.Startup, func() error {
|
||||||
var err error
|
var err error
|
||||||
var file *os.File
|
var file io.Writer
|
||||||
|
|
||||||
if handler.LogFile == "stdout" {
|
if handler.LogFile == "stdout" {
|
||||||
file = os.Stdout
|
file = os.Stdout
|
||||||
} else if handler.LogFile == "stderr" {
|
} else if handler.LogFile == "stderr" {
|
||||||
file = os.Stderr
|
file = os.Stderr
|
||||||
|
} else if handler.LogFile == "syslog" {
|
||||||
|
file, err = gsyslog.NewLogger(gsyslog.LOG_ERR, "SYSLOG", "caddy")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else if handler.LogFile != "" {
|
} else if handler.LogFile != "" {
|
||||||
file, err = os.OpenFile(handler.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
file, err = os.OpenFile(handler.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package setup
|
package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-syslog"
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
caddylog "github.com/mholt/caddy/middleware/log"
|
caddylog "github.com/mholt/caddy/middleware/log"
|
||||||
"github.com/mholt/caddy/server"
|
"github.com/mholt/caddy/server"
|
||||||
|
@ -20,12 +22,17 @@ func Log(c *Controller) (middleware.Middleware, error) {
|
||||||
c.Startup = append(c.Startup, func() error {
|
c.Startup = append(c.Startup, func() error {
|
||||||
for i := 0; i < len(rules); i++ {
|
for i := 0; i < len(rules); i++ {
|
||||||
var err error
|
var err error
|
||||||
var file *os.File
|
var file io.Writer
|
||||||
|
|
||||||
if rules[i].OutputFile == "stdout" {
|
if rules[i].OutputFile == "stdout" {
|
||||||
file = os.Stdout
|
file = os.Stdout
|
||||||
} else if rules[i].OutputFile == "stderr" {
|
} else if rules[i].OutputFile == "stderr" {
|
||||||
file = os.Stderr
|
file = os.Stderr
|
||||||
|
} else if rules[i].OutputFile == "syslog" {
|
||||||
|
file, err = gsyslog.NewLogger(gsyslog.LOG_NOTICE, "SYSLOG", "caddy")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
file, err = os.OpenFile(rules[i].OutputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
file, err = os.OpenFile(rules[i].OutputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue