dendrite/common: Move logrus configuration to common
MODIFY
src/github.com/matrix-org/dendrite/cmd/dendrite-clientapi/main.go
src/github.com/matrix-org/dendrite/cmd/dendrite-clientapi/main.go
@@ -3,34 +3,18 @@ package main
import (
"net/http"
"os"
- "path/filepath"
"golang.org/x/crypto/ed25519"
"github.com/matrix-org/dendrite/clientapi/config"
"github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/clientapi/routing"
+ "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/api"
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() {
bindAddr := os.Getenv("BIND_ADDRESS")
if bindAddr == "" {
@@ -38,7 +22,7 @@ func main() {
}
logDir := os.Getenv("LOG_DIR")
if logDir != "" {
- setupLogging(logDir)
+ common.SetupLogging(logDir)
}
// TODO: Rather than generating a new key on every startup, we should be

MODIFY
src/github.com/matrix-org/dendrite/cmd/dendrite-sync-server/main.go
src/github.com/matrix-org/dendrite/cmd/dendrite-sync-server/main.go
@@ -5,8 +5,8 @@ import (
"io/ioutil"
"net/http"
"os"
- "path/filepath"
+ "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/syncserver/config"
"github.com/matrix-org/dendrite/syncserver/consumers"
"github.com/matrix-org/dendrite/syncserver/routing"
@@ -14,28 +14,12 @@ import (
"github.com/matrix-org/dendrite/syncserver/sync"
log "github.com/Sirupsen/logrus"
- "github.com/matrix-org/dugong"
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 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) {
contents, err := ioutil.ReadFile(configPath)
if err != nil {
@@ -65,7 +49,7 @@ func main() {
}
logDir := os.Getenv("LOG_DIR")
if logDir != "" {
- setupLogging(logDir)
+ common.SetupLogging(logDir)
}
log.Info("sync server config: ", cfg)

ADD
src/github.com/matrix-org/dendrite/common/log.go
+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},
+ ))
+}

dendrite/common: Move logrus configuration to common