From 6e1eaf7b9083c4846ed68aa8a8c5255e8b71bbe2 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 19 Jan 2018 20:06:04 +0100 Subject: [PATCH] More flexible logging; add support for the Windows event log --- README.md | 7 ++++--- dnscrypt-proxy/config.go | 12 ++++++++++++ dnscrypt-proxy/dnscrypt-proxy.toml | 15 +++++++++++++++ dnscrypt-proxy/main.go | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 84f7bfe6..2a26cc70 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ dnscrypt-proxy is a flexible DNS proxy. It runs on your computer or router, and ### Setting up dnscrypt-proxy -1) Modify the [`dnscrypt-proxy.toml`](https://raw.githubusercontent.com/jedisct1/dnscrypt-proxy/master/dnscrypt-proxy/dnscrypt-proxy.toml) configuration file according to your needs. -2) Make sure that nothing else is already listening to port 53 on your system and run (in a console with elevated privileges on Windows) the `dnscrypt-proxy` application. Change your DNS settings to the configured IP address and check that everything works as expected. A DNS query for `resolver.00f.net` should return one of the chosen DNS servers instead of your ISP's resolver. -3) Register as a system service (see below). +1. Modify the [`dnscrypt-proxy.toml`](https://raw.githubusercontent.com/jedisct1/dnscrypt-proxy/master/dnscrypt-proxy/dnscrypt-proxy.toml) configuration file according to your needs. +2. Make sure that nothing else is already listening to port 53 on your system and run (in a console with elevated privileges on Windows) the `dnscrypt-proxy` application. Change your DNS settings to the configured IP address and check that everything works as expected. A DNS query for `resolver.00f.net` should return one of the chosen DNS servers instead of your ISP's resolver. +3. Register as a system service (see below). ### Installing as a system service (Windows, Linux, MacOS) @@ -64,6 +64,7 @@ The current 2.0.0 beta version includes all the major features from dnscrypt-pro | Built-in system installer | Only on Windows | Install/uninstall/start/stop/restart as a service on Windows, Linux/(systemd,Upstart,SysV), and macOS/launchd | | Built-in servers latency benchmark | No | Yes | | Query type filter: only log a relevant set of query types | No | Yes | +| Support for the Windows Event Log | No | Yes | ## Planned features diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index 70d56bdf..6152e06c 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -13,6 +13,9 @@ import ( ) type Config struct { + LogLevel int `toml:"log_level"` + LogFile *string `toml:"log_file"` + UseSyslog bool `toml:"use_syslog"` ServerNames []string `toml:"server_names"` ListenAddresses []string `toml:"listen_addresses"` Daemonize bool @@ -38,6 +41,7 @@ type Config struct { func newConfig() Config { return Config{ + LogLevel: int(dlog.LogLevel()), ListenAddresses: []string{"127.0.0.1:53"}, Timeout: 2500, CertRefreshDelay: 30, @@ -98,6 +102,14 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error { if _, err := toml.DecodeFile(*configFile, &config); err != nil { return err } + if config.LogLevel >= 0 && config.LogLevel < int(dlog.SeverityLast) { + dlog.SetLogLevel(dlog.Severity(config.LogLevel)) + } + if config.UseSyslog { + dlog.UseSyslog(true) + } else if config.LogFile != nil { + dlog.UseLogFile(*config.LogFile) + } proxy.timeout = time.Duration(config.Timeout) * time.Millisecond proxy.mainProto = "udp" if config.ForceTCP { diff --git a/dnscrypt-proxy/dnscrypt-proxy.toml b/dnscrypt-proxy/dnscrypt-proxy.toml index 7cfd3295..f68f8eb2 100644 --- a/dnscrypt-proxy/dnscrypt-proxy.toml +++ b/dnscrypt-proxy/dnscrypt-proxy.toml @@ -59,6 +59,21 @@ force_tcp = false timeout = 2500 +# Log level (0-6, default: 2 - 0 is very verbose, 6 only contains fatal errors) + +# log_level = 2 + + +# log file for the application + +# log_file = "dnscrypt-proxy.log" + + +# Use the system logger (syslog on Unix, Event Log on Windows) + +# use_syslog = true + + ## Delay, in minutes, after which certificates are reloaded cert_refresh_delay = 30 diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index 1e7b8df9..654c0864 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -16,7 +16,7 @@ import ( "golang.org/x/crypto/curve25519" ) -const AppVersion = "2.0.0beta3" +const AppVersion = "2.0.0beta4" type Proxy struct { proxyPublicKey [32]byte