Skip to content

Commit

Permalink
Merge branch 'master' into feature/1744
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemBaskal committed Jun 5, 2020
2 parents bb5a77f + 5ce98bd commit 912a80b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
17 changes: 10 additions & 7 deletions client/src/components/ui/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import './Version.css';

const Version = (props) => {
const {
dnsVersion = 'undefined', processingVersion, t, checkUpdateFlag,
dnsVersion, processingVersion, t, checkUpdateFlag,
} = props;

return (
<div className="version">
<div className="version__text">
<Trans>version</Trans>:&nbsp;
<span className="version__value" title={dnsVersion}>{dnsVersion}</span>
{dnsVersion
&& <>
<Trans>version</Trans>:&nbsp;
<span className="version__value" title={dnsVersion}>{dnsVersion}</span>
</>}
{checkUpdateFlag && <button
type="button"
className="btn btn-icon btn-icon-sm btn-outline-primary btn-sm ml-2"
Expand All @@ -31,10 +34,10 @@ const Version = (props) => {
};

Version.propTypes = {
dnsVersion: PropTypes.string.isRequired,
getVersion: PropTypes.func.isRequired,
processingVersion: PropTypes.bool.isRequired,
checkUpdateFlag: PropTypes.bool.isRequired,
dnsVersion: PropTypes.string,
getVersion: PropTypes.func,
processingVersion: PropTypes.bool,
checkUpdateFlag: PropTypes.bool,
t: PropTypes.func.isRequired,
};

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ require (
golang.org/x/crypto v0.0.0-20200403201458-baeed622b8d8
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.2.8
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
16 changes: 14 additions & 2 deletions home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ const (

// logSettings
type logSettings struct {
LogFile string `yaml:"log_file"` // Path to the log file. If empty, write to stdout. If "syslog", writes to syslog
Verbose bool `yaml:"verbose"` // If true, verbose logging is enabled
LogCompress bool `yaml:"log_compress"` // Compress determines if the rotated log files should be compressed using gzip (default: false)
LogLocalTime bool `yaml:"log_localtime"` // If the time used for formatting the timestamps in is the computer's local time (default: false [UTC])
LogMaxBackups int `yaml:"log_max_backups"` // Maximum number of old log files to retain (MaxAge may still cause them to get deleted)
LogMaxSize int `yaml:"log_max_size"` // Maximum size in megabytes of the log file before it gets rotated (default 100 MB)
LogMaxAge int `yaml:"log_max_age"` // MaxAge is the maximum number of days to retain old log files
LogFile string `yaml:"log_file"` // Path to the log file. If empty, write to stdout. If "syslog", writes to syslog
Verbose bool `yaml:"verbose"` // If true, verbose logging is enabled
}

// configuration is loaded from YAML
Expand Down Expand Up @@ -131,6 +136,13 @@ var config = configuration{
LeaseDuration: 86400,
ICMPTimeout: 1000,
},
logSettings: logSettings{
LogCompress: false,
LogLocalTime: false,
LogMaxBackups: 0,
LogMaxSize: 100,
LogMaxAge: 0,
},
SchemaVersion: currentSchemaVersion,
}

Expand Down
26 changes: 23 additions & 3 deletions home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"syscall"
"time"

"gopkg.in/natefinch/lumberjack.v2"

"github.com/AdguardTeam/AdGuardHome/util"

"github.com/joomcode/errorx"
Expand Down Expand Up @@ -396,13 +398,22 @@ func configureLogger(args options) {
ls := getLogSettings()

// command-line arguments can override config settings
if args.verbose {
if args.verbose || config.Verbose {
ls.Verbose = true
}
if args.logFile != "" {
ls.LogFile = args.logFile
} else if config.LogFile != "" {
ls.LogFile = config.LogFile
}

// Handle default log settings overrides
ls.LogCompress = config.LogCompress
ls.LogLocalTime = config.LogLocalTime
ls.LogMaxBackups = config.LogMaxBackups
ls.LogMaxSize = config.LogMaxSize
ls.LogMaxAge = config.LogMaxAge

// log.SetLevel(log.INFO) - default
if ls.Verbose {
log.SetLevel(log.DEBUG)
Expand All @@ -414,6 +425,7 @@ func configureLogger(args options) {
ls.LogFile = configSyslog
}

// logs are written to stdout (default)
if ls.LogFile == "" {
return
}
Expand All @@ -430,11 +442,19 @@ func configureLogger(args options) {
logFilePath = ls.LogFile
}

file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
_, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("cannot create a log file: %s", err)
}
log.SetOutput(file)

log.SetOutput(&lumberjack.Logger{
Filename: logFilePath,
Compress: ls.LogCompress, // disabled by default
LocalTime: ls.LogLocalTime,
MaxBackups: ls.LogMaxBackups,
MaxSize: ls.LogMaxSize, // megabytes
MaxAge: ls.LogMaxAge, //days
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion querylog/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (l *queryLog) getClientIP(clientIP string) string {
ip := net.ParseIP(clientIP)
if ip != nil {
ip4 := ip.To4()
const AnonymizeClientIP4Mask = 24
const AnonymizeClientIP4Mask = 16
const AnonymizeClientIP6Mask = 112
if ip4 != nil {
clientIP = ip4.Mask(net.CIDRMask(AnonymizeClientIP4Mask, 32)).String()
Expand Down
2 changes: 1 addition & 1 deletion stats/stats_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (s *statsCtx) getClientIP(clientIP string) string {
ip := net.ParseIP(clientIP)
if ip != nil {
ip4 := ip.To4()
const AnonymizeClientIP4Mask = 24
const AnonymizeClientIP4Mask = 16
const AnonymizeClientIP6Mask = 112
if ip4 != nil {
clientIP = ip4.Mask(net.CIDRMask(AnonymizeClientIP4Mask, 32)).String()
Expand Down

0 comments on commit 912a80b

Please sign in to comment.