Add logging options (#154)

* Add various log options

* Remove logFormat. Add UI for log config

* Fix UI boolean flags
This commit is contained in:
WithoutPants
2019-10-25 11:13:44 +11:00
committed by Leopere
parent f29509577a
commit 564786f968
9 changed files with 197 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import (
"golang.org/x/crypto/bcrypt"
"io/ioutil"
"github.com/spf13/viper"
"github.com/stashapp/stash/pkg/utils"
@@ -24,6 +25,12 @@ const Port = "port"
const CSSEnabled = "cssEnabled"
// Logging options
const LogFile = "logFile"
const LogOut = "logOut"
const LogLevel = "logLevel"
const LogAccess = "logAccess"
func Set(key string, value interface{}) {
viper.Set(key, value)
}
@@ -155,6 +162,48 @@ func GetCSSEnabled() bool {
return viper.GetBool(CSSEnabled)
}
// GetLogFile returns the filename of the file to output logs to.
// An empty string means that file logging will be disabled.
func GetLogFile() string {
return viper.GetString(LogFile)
}
// GetLogOut returns true if logging should be output to the terminal
// in addition to writing to a log file. Logging will be output to the
// terminal if file logging is disabled. Defaults to true.
func GetLogOut() bool {
ret := true
if viper.IsSet(LogOut) {
ret = viper.GetBool(LogOut)
}
return ret
}
// GetLogLevel returns the lowest log level to write to the log.
// Should be one of "Debug", "Info", "Warning", "Error"
func GetLogLevel() string {
const defaultValue = "Info"
value := viper.GetString(LogLevel)
if value != "Debug" && value != "Info" && value != "Warning" && value != "Error" {
value = defaultValue
}
return value
}
// GetLogAccess returns true if http requests should be logged to the terminal.
// HTTP requests are not logged to the log file. Defaults to true.
func GetLogAccess() bool {
ret := true
if viper.IsSet(LogAccess) {
ret = viper.GetBool(LogAccess)
}
return ret
}
func IsValid() bool {
setPaths := viper.IsSet(Stash) && viper.IsSet(Cache) && viper.IsSet(Generated) && viper.IsSet(Metadata)