Disable access log by default
Access logs aren't really useful during normal operation. Add a new flag -v to enable the verbose logging mode, which is still useful during the development. Also remove the log_file config because it's no longer useful.
This commit is contained in:
parent
8eec93e028
commit
60392e61c7
|
@ -31,9 +31,6 @@ static_directory=static
|
|||
# Empty value will disable the format selection in frontend.
|
||||
post_formats=PlainText:text/plain,HTML:text/html,Markdown:text/markdown,BBCode:text/bbcode
|
||||
|
||||
# Log file. Will log to stdout if value is empty.
|
||||
# log_file=log
|
||||
|
||||
# In single instance mode, bloat will not ask for instance domain name and
|
||||
# user will be directly redirected to login form. User login from other
|
||||
# instances is not allowed in this mode.
|
||||
|
|
|
@ -20,7 +20,6 @@ type config struct {
|
|||
TemplatesPath string
|
||||
CustomCSS string
|
||||
PostFormats []model.PostFormat
|
||||
LogFile string
|
||||
}
|
||||
|
||||
func (c *config) IsValid() bool {
|
||||
|
@ -97,7 +96,7 @@ func Parse(r io.Reader) (c *config, err error) {
|
|||
}
|
||||
c.PostFormats = formats
|
||||
case "log_file":
|
||||
c.LogFile = val
|
||||
// ignore
|
||||
default:
|
||||
return nil, errors.New("invalid config key " + key)
|
||||
}
|
||||
|
|
18
main.go
18
main.go
|
@ -26,6 +26,7 @@ func errExit(err error) {
|
|||
|
||||
func main() {
|
||||
configFile := flag.String("f", "", "config file")
|
||||
verbose := flag.Bool("v", false, "verbose mode")
|
||||
flag.Parse()
|
||||
|
||||
if len(*configFile) > 0 {
|
||||
|
@ -52,25 +53,12 @@ func main() {
|
|||
customCSS = "/static/" + customCSS
|
||||
}
|
||||
|
||||
var logger *log.Logger
|
||||
if len(config.LogFile) < 1 {
|
||||
logger = log.New(os.Stdout, "", log.LstdFlags)
|
||||
} else {
|
||||
lf, err := os.OpenFile(config.LogFile,
|
||||
os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
errExit(err)
|
||||
}
|
||||
defer lf.Close()
|
||||
logger = log.New(lf, "", log.LstdFlags)
|
||||
}
|
||||
|
||||
s := service.NewService(config.ClientName, config.ClientScope,
|
||||
config.ClientWebsite, customCSS, config.SingleInstance,
|
||||
config.PostFormats, renderer)
|
||||
handler := service.NewHandler(s, logger, config.StaticDirectory)
|
||||
handler := service.NewHandler(s, *verbose, config.StaticDirectory)
|
||||
|
||||
logger.Println("listening on", config.ListenAddress)
|
||||
log.Println("listening on", config.ListenAddress)
|
||||
err = http.ListenAndServe(config.ListenAddress, handler)
|
||||
if err != nil {
|
||||
errExit(err)
|
||||
|
|
|
@ -23,7 +23,7 @@ const (
|
|||
CSRF
|
||||
)
|
||||
|
||||
func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||
func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
|
||||
r := mux.NewRouter()
|
||||
|
||||
writeError := func(c *client, err error, t int, retry bool) {
|
||||
|
@ -48,10 +48,12 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||
r: req,
|
||||
}
|
||||
|
||||
if verbose {
|
||||
defer func(begin time.Time) {
|
||||
logger.Printf("path=%s, err=%v, took=%v\n",
|
||||
log.Printf("path=%s, err=%v, took=%v\n",
|
||||
req.URL.Path, err, time.Since(begin))
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
var ct string
|
||||
switch rt {
|
||||
|
|
Loading…
Reference in New Issue