提交 80100830 编写于 作者: R Robert Swain

dendrite/common: Move logrus configuration to common

上级 db428174
......@@ -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
......
......@@ -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)
......
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},
))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册