Remove LOG_DIR and use the configuration instead

Signed-off-by: Tristan Claverie <public@tclaverie.eu>
This commit is contained in:
Tristan Claverie 2017-12-18 01:19:05 +01:00
parent ae4992fa83
commit c26d23b89f
9 changed files with 35 additions and 29 deletions

View file

@ -17,7 +17,6 @@ package main
import (
"flag"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
@ -37,12 +36,11 @@ import (
)
var (
logDir = os.Getenv("LOG_DIR")
configPath = flag.String("config", "dendrite.yaml", "The path to the config file, For more information see the config file in this repository")
)
func main() {
common.SetupLogging(logDir)
common.SetupStdLogging()
flag.Parse()
@ -51,6 +49,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendriteClientAPI")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -17,7 +17,6 @@ package main
import (
"flag"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
@ -33,12 +32,11 @@ import (
)
var (
logDir = os.Getenv("LOG_DIR")
configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
)
func main() {
common.SetupLogging(logDir)
common.SetupStdLogging()
flag.Parse()
@ -50,6 +48,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendriteFederationAPI")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -17,7 +17,6 @@ package main
import (
"flag"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/common"
@ -35,7 +34,7 @@ import (
var configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
func main() {
common.SetupLogging(os.Getenv("LOG_DIR"))
common.SetupStdLogging()
flag.Parse()
@ -47,6 +46,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendriteFederationSender")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -17,7 +17,6 @@ package main
import (
"flag"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
@ -31,12 +30,11 @@ import (
)
var (
logDir = os.Getenv("LOG_DIR")
configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
)
func main() {
common.SetupLogging(logDir)
common.SetupStdLogging()
flag.Parse()
@ -48,6 +46,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendriteMediaAPI")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -19,7 +19,6 @@ import (
"database/sql"
"flag"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
@ -63,7 +62,6 @@ import (
)
var (
logDir = os.Getenv("LOG_DIR")
configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server")
httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server")
@ -72,7 +70,7 @@ var (
)
func main() {
common.SetupLogging(logDir)
common.SetupStdLogging()
flag.Parse()
@ -84,6 +82,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendriteMonolith")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -17,7 +17,6 @@ package main
import (
"flag"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
@ -35,7 +34,7 @@ import (
var configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
func main() {
common.SetupLogging(os.Getenv("LOG_DIR"))
common.SetupStdLogging()
flag.Parse()
@ -47,6 +46,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendritePublicRoomsAPI")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -18,7 +18,6 @@ import (
"flag"
"net/http"
_ "net/http/pprof"
"os"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/common/config"
@ -32,12 +31,11 @@ import (
)
var (
logDir = os.Getenv("LOG_DIR")
configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
)
func main() {
common.SetupLogging(logDir)
common.SetupStdLogging()
flag.Parse()
@ -49,6 +47,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendriteRoomServer")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -18,7 +18,6 @@ import (
"context"
"flag"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
@ -39,7 +38,7 @@ import (
var configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
func main() {
common.SetupLogging(os.Getenv("LOG_DIR"))
common.SetupStdLogging()
flag.Parse()
@ -51,6 +50,8 @@ func main() {
log.Fatalf("Invalid config file: %s", err)
}
common.SetupFileLogging(string(cfg.Logging.FPath), cfg.Derived.LogLevel)
closer, err := cfg.SetupTracing("DendriteSyncAPI")
if err != nil {
log.WithError(err).Fatalf("Failed to start tracer")

View file

@ -16,7 +16,7 @@ package common
import (
"os"
"path/filepath"
"path"
"github.com/matrix-org/dugong"
"github.com/sirupsen/logrus"
@ -31,8 +31,8 @@ func (f utcFormatter) Format(entry *logrus.Entry) ([]byte, error) {
return f.Formatter.Format(entry)
}
// SetupLogging configures the logging format and destination(s).
func SetupLogging(logDir string) {
// SetupStdLogging configures the logging format to standard output. Typically, it is called when the config is not yet loaded.
func SetupStdLogging() {
logrus.SetFormatter(&utcFormatter{
&logrus.TextFormatter{
TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
@ -42,12 +42,15 @@ func SetupLogging(logDir string) {
DisableSorting: false,
},
})
if logDir != "" {
_ = os.Mkdir(logDir, os.ModePerm)
}
// SetupFileLogging configures the logging format to a file.
func SetupFileLogging(logFile string, logLevel logrus.Level) {
logrus.SetLevel(logLevel)
if logFile != "" {
_ = os.MkdirAll(path.Dir(logFile), os.ModePerm)
logrus.AddHook(dugong.NewFSHook(
filepath.Join(logDir, "info.log"),
filepath.Join(logDir, "warn.log"),
filepath.Join(logDir, "error.log"),
logFile,
&utcFormatter{
&logrus.TextFormatter{
TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",