mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48:27 +00:00
Implement logging to file via dugong (#12)
This commit is contained in:
parent
0bd3af8115
commit
5c34caa1c1
1 changed files with 23 additions and 1 deletions
|
@ -1,18 +1,40 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/dendrite/clientapi/routing"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/routing"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/matrix-org/dugong"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func setupLogging(logDir string) {
|
||||||
|
_ = os.Mkdir(logDir, os.ModePerm)
|
||||||
|
log.AddHook(dugong.NewFSHook(
|
||||||
|
filepath.Join(logDir, "info.log"),
|
||||||
|
filepath.Join(logDir, "warn.log"),
|
||||||
|
filepath.Join(logDir, "error.log"),
|
||||||
|
&log.TextFormatter{
|
||||||
|
TimestampFormat: "2006-01-02 15:04:05.000000",
|
||||||
|
DisableColors: true,
|
||||||
|
DisableTimestamp: false,
|
||||||
|
DisableSorting: false,
|
||||||
|
}, &dugong.DailyRotationSchedule{GZip: true},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bindAddr := os.Getenv("BIND_ADDRESS")
|
bindAddr := os.Getenv("BIND_ADDRESS")
|
||||||
if bindAddr == "" {
|
if bindAddr == "" {
|
||||||
log.Panic("No BIND_ADDRESS environment variable found.")
|
log.Panic("No BIND_ADDRESS environment variable found.")
|
||||||
}
|
}
|
||||||
|
logDir := os.Getenv("LOG_DIR")
|
||||||
|
if logDir != "" {
|
||||||
|
setupLogging(logDir)
|
||||||
|
}
|
||||||
log.Info("Starting clientapi")
|
log.Info("Starting clientapi")
|
||||||
routing.Setup(http.DefaultServeMux, http.DefaultClient)
|
routing.Setup(http.DefaultServeMux, http.DefaultClient)
|
||||||
log.Fatal(http.ListenAndServe(bindAddr, nil))
|
log.Fatal(http.ListenAndServe(bindAddr, nil))
|
||||||
|
|
Loading…
Reference in a new issue