mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48:27 +00:00
dendrite/common: Move logrus configuration to common
This commit is contained in:
parent
db428174d2
commit
8010083026
3 changed files with 29 additions and 36 deletions
|
@ -3,34 +3,18 @@ package main
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/config"
|
"github.com/matrix-org/dendrite/clientapi/config"
|
||||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||||
"github.com/matrix-org/dendrite/clientapi/routing"
|
"github.com/matrix-org/dendrite/clientapi/routing"
|
||||||
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
|
||||||
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 == "" {
|
||||||
|
@ -38,7 +22,7 @@ func main() {
|
||||||
}
|
}
|
||||||
logDir := os.Getenv("LOG_DIR")
|
logDir := os.Getenv("LOG_DIR")
|
||||||
if logDir != "" {
|
if logDir != "" {
|
||||||
setupLogging(logDir)
|
common.SetupLogging(logDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rather than generating a new key on every startup, we should be
|
// TODO: Rather than generating a new key on every startup, we should be
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/syncserver/config"
|
"github.com/matrix-org/dendrite/syncserver/config"
|
||||||
"github.com/matrix-org/dendrite/syncserver/consumers"
|
"github.com/matrix-org/dendrite/syncserver/consumers"
|
||||||
"github.com/matrix-org/dendrite/syncserver/routing"
|
"github.com/matrix-org/dendrite/syncserver/routing"
|
||||||
|
@ -14,28 +14,12 @@ import (
|
||||||
"github.com/matrix-org/dendrite/syncserver/sync"
|
"github.com/matrix-org/dendrite/syncserver/sync"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/matrix-org/dugong"
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configPath = flag.String("config", "sync-server-config.yaml", "The path to the config file. For more information, see the config file in this repository.")
|
var configPath = flag.String("config", "sync-server-config.yaml", "The path to the config file. For more information, see the config file in this repository.")
|
||||||
var bindAddr = flag.String("listen", ":4200", "The port to listen on.")
|
var bindAddr = flag.String("listen", ":4200", "The port to listen on.")
|
||||||
|
|
||||||
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 loadConfig(configPath string) (*config.Sync, error) {
|
func loadConfig(configPath string) (*config.Sync, error) {
|
||||||
contents, err := ioutil.ReadFile(configPath)
|
contents, err := ioutil.ReadFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -65,7 +49,7 @@ func main() {
|
||||||
}
|
}
|
||||||
logDir := os.Getenv("LOG_DIR")
|
logDir := os.Getenv("LOG_DIR")
|
||||||
if logDir != "" {
|
if logDir != "" {
|
||||||
setupLogging(logDir)
|
common.SetupLogging(logDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("sync server config: ", cfg)
|
log.Info("sync server config: ", cfg)
|
||||||
|
|
25
src/github.com/matrix-org/dendrite/common/log.go
Normal file
25
src/github.com/matrix-org/dendrite/common/log.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/matrix-org/dugong"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetupLogging configures the logging format and destination(s).
|
||||||
|
func SetupLogging(logDir string) {
|
||||||
|
_ = os.Mkdir(logDir, os.ModePerm)
|
||||||
|
logrus.AddHook(dugong.NewFSHook(
|
||||||
|
filepath.Join(logDir, "info.log"),
|
||||||
|
filepath.Join(logDir, "warn.log"),
|
||||||
|
filepath.Join(logDir, "error.log"),
|
||||||
|
&logrus.TextFormatter{
|
||||||
|
TimestampFormat: "2006-01-02 15:04:05.000000",
|
||||||
|
DisableColors: true,
|
||||||
|
DisableTimestamp: false,
|
||||||
|
DisableSorting: false,
|
||||||
|
}, &dugong.DailyRotationSchedule{GZip: true},
|
||||||
|
))
|
||||||
|
}
|
Loading…
Reference in a new issue