diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-clientapi/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-clientapi/main.go index 70df0a2d1887967be169e4c0b615057b3ed75d60..925c54d684d87558ac0038ae91f83d1ce85f0c57 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-clientapi/main.go +++ b/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 diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-server/main.go index fe74679a486ad22201fa295e42ab4c346cbeae36..a8451a45dd173c7f65b7b6bd8535d625ce9a020c 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-server/main.go +++ b/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) diff --git a/src/github.com/matrix-org/dendrite/common/log.go b/src/github.com/matrix-org/dendrite/common/log.go new file mode 100644 index 0000000000000000000000000000000000000000..a270a56ec38100d4aedf6cacf6e6949b31c90e8e --- /dev/null +++ b/src/github.com/matrix-org/dendrite/common/log.go @@ -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}, + )) +}