mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-21 20:29:20 +02:00
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.
|
# Empty value will disable the format selection in frontend.
|
||||||
post_formats=PlainText:text/plain,HTML:text/html,Markdown:text/markdown,BBCode:text/bbcode
|
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
|
# 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
|
# user will be directly redirected to login form. User login from other
|
||||||
# instances is not allowed in this mode.
|
# instances is not allowed in this mode.
|
||||||
|
|
|
@ -20,7 +20,6 @@ type config struct {
|
||||||
TemplatesPath string
|
TemplatesPath string
|
||||||
CustomCSS string
|
CustomCSS string
|
||||||
PostFormats []model.PostFormat
|
PostFormats []model.PostFormat
|
||||||
LogFile string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) IsValid() bool {
|
func (c *config) IsValid() bool {
|
||||||
|
@ -97,7 +96,7 @@ func Parse(r io.Reader) (c *config, err error) {
|
||||||
}
|
}
|
||||||
c.PostFormats = formats
|
c.PostFormats = formats
|
||||||
case "log_file":
|
case "log_file":
|
||||||
c.LogFile = val
|
// ignore
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("invalid config key " + key)
|
return nil, errors.New("invalid config key " + key)
|
||||||
}
|
}
|
||||||
|
|
18
main.go
18
main.go
|
@ -26,6 +26,7 @@ func errExit(err error) {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configFile := flag.String("f", "", "config file")
|
configFile := flag.String("f", "", "config file")
|
||||||
|
verbose := flag.Bool("v", false, "verbose mode")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if len(*configFile) > 0 {
|
if len(*configFile) > 0 {
|
||||||
|
@ -52,25 +53,12 @@ func main() {
|
||||||
customCSS = "/static/" + customCSS
|
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,
|
s := service.NewService(config.ClientName, config.ClientScope,
|
||||||
config.ClientWebsite, customCSS, config.SingleInstance,
|
config.ClientWebsite, customCSS, config.SingleInstance,
|
||||||
config.PostFormats, renderer)
|
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)
|
err = http.ListenAndServe(config.ListenAddress, handler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errExit(err)
|
errExit(err)
|
||||||
|
|
|
@ -23,7 +23,7 @@ const (
|
||||||
CSRF
|
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()
|
r := mux.NewRouter()
|
||||||
|
|
||||||
writeError := func(c *client, err error, t int, retry bool) {
|
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,
|
r: req,
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func(begin time.Time) {
|
if verbose {
|
||||||
logger.Printf("path=%s, err=%v, took=%v\n",
|
defer func(begin time.Time) {
|
||||||
req.URL.Path, err, time.Since(begin))
|
log.Printf("path=%s, err=%v, took=%v\n",
|
||||||
}(time.Now())
|
req.URL.Path, err, time.Since(begin))
|
||||||
|
}(time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
var ct string
|
var ct string
|
||||||
switch rt {
|
switch rt {
|
||||||
|
|
Loading…
Reference in New Issue