aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bloat.conf3
-rw-r--r--config/config.go3
-rw-r--r--main.go18
-rw-r--r--service/transport.go12
4 files changed, 11 insertions, 25 deletions
diff --git a/bloat.conf b/bloat.conf
index ddf18fc..f29e553 100644
--- a/bloat.conf
+++ b/bloat.conf
@@ -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.
diff --git a/config/config.go b/config/config.go
index a92d66f..141cb39 100644
--- a/config/config.go
+++ b/config/config.go
@@ -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)
}
diff --git a/main.go b/main.go
index b717b7d..657912d 100644
--- a/main.go
+++ b/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)
diff --git a/service/transport.go b/service/transport.go
index 5c6472c..dcf2990 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -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,
}
- defer func(begin time.Time) {
- logger.Printf("path=%s, err=%v, took=%v\n",
- req.URL.Path, err, time.Since(begin))
- }(time.Now())
+ if verbose {
+ defer func(begin time.Time) {
+ log.Printf("path=%s, err=%v, took=%v\n",
+ req.URL.Path, err, time.Since(begin))
+ }(time.Now())
+ }
var ct string
switch rt {