parent
04b49fd355
commit
8dd4612ea7
|
@ -406,7 +406,7 @@ cache_neg_max_ttl = 600
|
||||||
[query_log]
|
[query_log]
|
||||||
|
|
||||||
## Path to the query log file (absolute, or relative to the same directory as the config file)
|
## Path to the query log file (absolute, or relative to the same directory as the config file)
|
||||||
## On non-Windows systems, can be /dev/stdout to log to the standard output (also set log_files_max_size to 0)
|
## Can be set to /dev/stdout in order to log to the standard output.
|
||||||
|
|
||||||
# file = 'query.log'
|
# file = 'query.log'
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/jedisct1/dlog"
|
||||||
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Logger(logMaxSize int, logMaxAge int, logMaxBackups int, fileName string) io.Writer {
|
||||||
|
if fileName == "/dev/stdout" {
|
||||||
|
return os.Stdout
|
||||||
|
}
|
||||||
|
if st, _ := os.Stat(fileName); st != nil && !st.Mode().IsRegular() {
|
||||||
|
if st.Mode().IsDir() {
|
||||||
|
dlog.Fatalf("[%v] is a directory", fileName)
|
||||||
|
}
|
||||||
|
fp, err := os.OpenFile(fileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
dlog.Fatalf("Unable to access [%v]: [%v]", fileName, err)
|
||||||
|
}
|
||||||
|
return fp
|
||||||
|
}
|
||||||
|
logger := &lumberjack.Logger{LocalTime: true, MaxSize: logMaxSize, MaxAge: logMaxAge, MaxBackups: logMaxBackups, Filename: fileName, Compress: true}
|
||||||
|
|
||||||
|
return logger
|
||||||
|
}
|
|
@ -11,7 +11,6 @@ import (
|
||||||
iradix "github.com/hashicorp/go-immutable-radix"
|
iradix "github.com/hashicorp/go-immutable-radix"
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginBlockIP struct {
|
type PluginBlockIP struct {
|
||||||
|
@ -72,7 +71,7 @@ func (plugin *PluginBlockIP) Init(proxy *Proxy) error {
|
||||||
if len(proxy.blockIPLogFile) == 0 {
|
if len(proxy.blockIPLogFile) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
plugin.logger = &lumberjack.Logger{LocalTime: true, MaxSize: proxy.logMaxSize, MaxAge: proxy.logMaxAge, MaxBackups: proxy.logMaxBackups, Filename: proxy.blockIPLogFile, Compress: true}
|
plugin.logger = Logger(proxy.logMaxSize, proxy.logMaxAge, proxy.logMaxBackups, proxy.blockIPLogFile)
|
||||||
plugin.format = proxy.blockIPFormat
|
plugin.format = proxy.blockIPFormat
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlockedNames struct {
|
type BlockedNames struct {
|
||||||
|
@ -126,7 +125,7 @@ func (plugin *PluginBlockName) Init(proxy *Proxy) error {
|
||||||
if len(proxy.blockNameLogFile) == 0 {
|
if len(proxy.blockNameLogFile) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
blockedNames.logger = &lumberjack.Logger{LocalTime: true, MaxSize: proxy.logMaxSize, MaxAge: proxy.logMaxAge, MaxBackups: proxy.logMaxBackups, Filename: proxy.blockNameLogFile, Compress: true}
|
blockedNames.logger = Logger(proxy.logMaxSize, proxy.logMaxAge, proxy.logMaxBackups, proxy.blockNameLogFile)
|
||||||
blockedNames.format = proxy.blockNameFormat
|
blockedNames.format = proxy.blockNameFormat
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginNxLog struct {
|
type PluginNxLog struct {
|
||||||
|
@ -26,7 +25,7 @@ func (plugin *PluginNxLog) Description() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *PluginNxLog) Init(proxy *Proxy) error {
|
func (plugin *PluginNxLog) Init(proxy *Proxy) error {
|
||||||
plugin.logger = &lumberjack.Logger{LocalTime: true, MaxSize: proxy.logMaxSize, MaxAge: proxy.logMaxAge, MaxBackups: proxy.logMaxBackups, Filename: proxy.nxLogFile, Compress: true}
|
plugin.logger = Logger(proxy.logMaxSize, proxy.logMaxAge, proxy.logMaxBackups, proxy.nxLogFile)
|
||||||
plugin.format = proxy.nxLogFormat
|
plugin.format = proxy.nxLogFormat
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginQueryLog struct {
|
type PluginQueryLog struct {
|
||||||
|
@ -28,7 +27,7 @@ func (plugin *PluginQueryLog) Description() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *PluginQueryLog) Init(proxy *Proxy) error {
|
func (plugin *PluginQueryLog) Init(proxy *Proxy) error {
|
||||||
plugin.logger = &lumberjack.Logger{LocalTime: true, MaxSize: proxy.logMaxSize, MaxAge: proxy.logMaxAge, MaxBackups: proxy.logMaxBackups, Filename: proxy.queryLogFile, Compress: true}
|
plugin.logger = Logger(proxy.logMaxSize, proxy.logMaxAge, proxy.logMaxBackups, proxy.queryLogFile)
|
||||||
plugin.format = proxy.queryLogFormat
|
plugin.format = proxy.queryLogFormat
|
||||||
plugin.ignoredQtypes = proxy.queryLogIgnoredQtypes
|
plugin.ignoredQtypes = proxy.queryLogIgnoredQtypes
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginWhitelistName struct {
|
type PluginWhitelistName struct {
|
||||||
|
@ -68,7 +67,7 @@ func (plugin *PluginWhitelistName) Init(proxy *Proxy) error {
|
||||||
if len(proxy.whitelistNameLogFile) == 0 {
|
if len(proxy.whitelistNameLogFile) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
plugin.logger = &lumberjack.Logger{LocalTime: true, MaxSize: proxy.logMaxSize, MaxAge: proxy.logMaxAge, MaxBackups: proxy.logMaxBackups, Filename: proxy.whitelistNameLogFile, Compress: true}
|
plugin.logger = Logger(proxy.logMaxSize, proxy.logMaxAge, proxy.logMaxBackups, proxy.whitelistNameLogFile)
|
||||||
plugin.format = proxy.whitelistNameFormat
|
plugin.format = proxy.whitelistNameFormat
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue