mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 10:33:11 -06:00
zerolog - first apps
This commit is contained in:
parent
2b34f88fde
commit
e064ee5058
|
|
@ -29,9 +29,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/setup"
|
"github.com/matrix-org/dendrite/setup"
|
||||||
|
|
@ -73,6 +74,8 @@ var cl = http.Client{
|
||||||
Transport: http.DefaultTransport,
|
Transport: http.DefaultTransport,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var logger = zerolog.New(os.Stdout).With().Timestamp().Logger()
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
name := os.Args[0]
|
name := os.Args[0]
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
|
|
@ -82,11 +85,11 @@ func main() {
|
||||||
cfg := setup.ParseFlags(true)
|
cfg := setup.ParseFlags(true)
|
||||||
|
|
||||||
if *resetPassword {
|
if *resetPassword {
|
||||||
logrus.Fatalf("The reset-password flag has been replaced by the POST /_dendrite/admin/resetPassword/{localpart} admin API.")
|
logger.Fatal().Msgf("The reset-password flag has been replaced by the POST /_dendrite/admin/resetPassword/{localpart} admin API.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.ClientAPI.RegistrationSharedSecret == "" {
|
if cfg.ClientAPI.RegistrationSharedSecret == "" {
|
||||||
logrus.Fatalln("Shared secret registration is not enabled, enable it by setting a shared secret in the config: 'client_api.registration_shared_secret'")
|
logger.Fatal().Msgf("Shared secret registration is not enabled, enable it by setting a shared secret in the config: 'client_api.registration_shared_secret'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *username == "" {
|
if *username == "" {
|
||||||
|
|
@ -95,17 +98,17 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := internal.ValidateUsername(*username, cfg.Global.ServerName); err != nil {
|
if err := internal.ValidateUsername(*username, cfg.Global.ServerName); err != nil {
|
||||||
logrus.WithError(err).Error("Specified username is invalid")
|
logger.Error().Err(err).Msg("Specified username is invalid")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pass, err := getPassword(*password, *pwdFile, *pwdStdin, os.Stdin)
|
pass, err := getPassword(*password, *pwdFile, *pwdStdin, os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalln(err)
|
logger.Fatal().Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = internal.ValidatePassword(pass); err != nil {
|
if err = internal.ValidatePassword(pass); err != nil {
|
||||||
logrus.WithError(err).Error("Specified password is invalid")
|
logger.Error().Err(err).Msg("Specified password is invalid")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,10 +116,10 @@ func main() {
|
||||||
|
|
||||||
accessToken, err := sharedSecretRegister(cfg.ClientAPI.RegistrationSharedSecret, *serverURL, *username, pass, *isAdmin)
|
accessToken, err := sharedSecretRegister(cfg.ClientAPI.RegistrationSharedSecret, *serverURL, *username, pass, *isAdmin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalln("Failed to create the account:", err.Error())
|
logger.Fatal().Err(err).Msg("Failed to create the account.")
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("Created account: %s (AccessToken: %s)", *username, accessToken)
|
logger.Info().Msgf("Created account: %s (AccessToken: %s)", *username, accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sharedSecretRegistrationRequest struct {
|
type sharedSecretRegistrationRequest struct {
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ func main() {
|
||||||
cfg.MediaAPI.BasePath = config.Path(filepath.Join(*dirPath, "media"))
|
cfg.MediaAPI.BasePath = config.Path(filepath.Join(*dirPath, "media"))
|
||||||
cfg.Global.JetStream.StoragePath = config.Path(*dirPath)
|
cfg.Global.JetStream.StoragePath = config.Path(*dirPath)
|
||||||
cfg.SyncAPI.Fulltext.IndexPath = config.Path(filepath.Join(*dirPath, "searchindex"))
|
cfg.SyncAPI.Fulltext.IndexPath = config.Path(filepath.Join(*dirPath, "searchindex"))
|
||||||
cfg.Logging = []config.LogrusHook{
|
cfg.Logging = []config.LogHook{
|
||||||
{
|
{
|
||||||
Type: "file",
|
Type: "file",
|
||||||
Level: "info",
|
Level: "info",
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
|
|
@ -56,7 +55,7 @@ func main() {
|
||||||
|
|
||||||
if *tlsCertFile != "" || *tlsKeyFile != "" {
|
if *tlsCertFile != "" || *tlsKeyFile != "" {
|
||||||
if *tlsCertFile == "" || *tlsKeyFile == "" {
|
if *tlsCertFile == "" || *tlsKeyFile == "" {
|
||||||
log.Fatal("Zero or both of --tls-key and --tls-cert must be supplied")
|
panic("Zero or both of --tls-key and --tls-cert must be supplied")
|
||||||
}
|
}
|
||||||
if *authorityCertFile == "" && *authorityKeyFile == "" {
|
if *authorityCertFile == "" && *authorityKeyFile == "" {
|
||||||
if err := test.NewTLSKey(*tlsKeyFile, *tlsCertFile, *keySize); err != nil {
|
if err := test.NewTLSKey(*tlsKeyFile, *tlsCertFile, *keySize); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ var difference = flag.Bool("difference", false, "whether to calculate the differ
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cfg := setup.ParseFlags(true)
|
cfg := setup.ParseFlags(true)
|
||||||
cfg.Logging = append(cfg.Logging[:0], config.LogrusHook{
|
cfg.Logging = append(cfg.Logging[:0], config.LogHook{
|
||||||
Type: "std",
|
Type: "std",
|
||||||
Level: "error",
|
Level: "error",
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -27,44 +27,45 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
"github.com/matrix-org/dugong"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
log "github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// logrus is using a global variable when we're using `logrus.AddHook`
|
// logrus is using a global variable when we're using `logrus.AddHook`
|
||||||
// this unfortunately results in us adding the same hook multiple times.
|
// this unfortunately results in us adding the same hook multiple times.
|
||||||
// This map ensures we only ever add one level hook.
|
// This map ensures we only ever add one level hook.
|
||||||
var stdLevelLogAdded = make(map[logrus.Level]bool)
|
var stdLevelLogAdded = make(map[zerolog.Level]bool)
|
||||||
var levelLogAddedMu = &sync.Mutex{}
|
var levelLogAddedMu = &sync.Mutex{}
|
||||||
|
|
||||||
type utcFormatter struct {
|
type utcFormatter struct {
|
||||||
logrus.Formatter
|
zerolog.Formatter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f utcFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
func (f utcFormatter) Format(entry *zerolog.Event) ([]byte, error) {
|
||||||
entry.Time = entry.Time.UTC()
|
return f.Format(entry)
|
||||||
return f.Formatter.Format(entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logrus hook which wraps another hook and filters log entries according to their level.
|
// Logrus hook which wraps another hook and filters log entries according to their level.
|
||||||
// (Note that we cannot use solely logrus.SetLevel, because Dendrite supports multiple
|
// (Note that we cannot use solely logrus.SetLevel, because Dendrite supports multiple
|
||||||
// levels of logging at the same time.)
|
// levels of logging at the same time.)
|
||||||
type logLevelHook struct {
|
type logLevelHook struct {
|
||||||
level logrus.Level
|
level zerolog.Level
|
||||||
logrus.Hook
|
zerolog.Hook
|
||||||
}
|
}
|
||||||
|
|
||||||
// Levels returns all the levels supported by this hook.
|
// Levels returns all the levels supported by this hook.
|
||||||
func (h *logLevelHook) Levels() []logrus.Level {
|
func (h *logLevelHook) Levels() []zerolog.Level {
|
||||||
levels := make([]logrus.Level, 0)
|
levels := make([]zerolog.Level, 0)
|
||||||
|
var level zerolog.Level = -1
|
||||||
for _, level := range logrus.AllLevels {
|
for level <= 5 {
|
||||||
if level <= h.level {
|
if level <= h.level {
|
||||||
levels = append(levels, level)
|
levels = append(levels, level)
|
||||||
}
|
}
|
||||||
|
level = level + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return levels
|
return levels
|
||||||
|
|
@ -103,9 +104,14 @@ func SetupPprof() {
|
||||||
func SetupStdLogging() {
|
func SetupStdLogging() {
|
||||||
levelLogAddedMu.Lock()
|
levelLogAddedMu.Lock()
|
||||||
defer levelLogAddedMu.Unlock()
|
defer levelLogAddedMu.Unlock()
|
||||||
logrus.SetReportCaller(true)
|
//zerolog.SetReportCaller(true)
|
||||||
logrus.SetFormatter(&utcFormatter{
|
//TimeFieldFormat => dont need
|
||||||
&logrus.TextFormatter{
|
//DisableColors => dont need
|
||||||
|
//DisableTimestamp => dont need
|
||||||
|
//Quo0teEmptyFields => dont need
|
||||||
|
//callprettyfier => what?
|
||||||
|
/*zerolog.Formatter(&utcFormatter{
|
||||||
|
&zerolog.TextFormatter{
|
||||||
TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
|
TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
|
||||||
FullTimestamp: true,
|
FullTimestamp: true,
|
||||||
DisableColors: false,
|
DisableColors: false,
|
||||||
|
|
@ -113,46 +119,39 @@ func SetupStdLogging() {
|
||||||
QuoteEmptyFields: true,
|
QuoteEmptyFields: true,
|
||||||
CallerPrettyfier: callerPrettyfier,
|
CallerPrettyfier: callerPrettyfier,
|
||||||
},
|
},
|
||||||
})
|
})*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// File type hooks should be provided a path to a directory to store log files
|
// File type hooks should be provided a path to a directory to store log files
|
||||||
func checkFileHookParams(params map[string]interface{}) {
|
func checkFileHookParams(params map[string]interface{}) {
|
||||||
path, ok := params["path"]
|
path, ok := params["path"]
|
||||||
if !ok {
|
if !ok {
|
||||||
logrus.Fatalf("Expecting a parameter \"path\" for logging hook of type \"file\"")
|
log.Fatal().Msg("Expecting a parameter \"path\" for logging hook of type \"file\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := path.(string); !ok {
|
if _, ok := path.(string); !ok {
|
||||||
logrus.Fatalf("Parameter \"path\" for logging hook of type \"file\" should be a string")
|
log.Fatal().Msg("Parameter \"path\" for logging hook of type \"file\" should be a string")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a new FSHook to the logger. Each component will log in its own file
|
// Add a new FSHook to the logger. Each component will log in its own file
|
||||||
func setupFileHook(hook config.LogrusHook, level logrus.Level) {
|
func setupFileHook(hook config.LogHook, level zerolog.Level) {
|
||||||
dirPath := (hook.Params["path"]).(string)
|
dirPath := (hook.Params["path"]).(string)
|
||||||
fullPath := filepath.Join(dirPath, "dendrite.log")
|
fullPath := filepath.Join(dirPath, "dendrite.log")
|
||||||
|
|
||||||
if err := os.MkdirAll(path.Dir(fullPath), os.ModePerm); err != nil {
|
if err := os.MkdirAll(path.Dir(fullPath), os.ModePerm); err != nil {
|
||||||
logrus.Fatalf("Couldn't create directory %s: %q", path.Dir(fullPath), err)
|
log.Fatal().Msgf("Couldn't create directory %s: %q", path.Dir(fullPath), err)
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
logrus.AddHook(&logLevelHook{
|
log.Hook(&logLevelHook{
|
||||||
level,
|
level,
|
||||||
dugong.NewFSHook(
|
dugong.NewFSHook(
|
||||||
fullPath,
|
fullPath,
|
||||||
&utcFormatter{
|
&utcFormatter{log.Logger},
|
||||||
&logrus.TextFormatter{
|
|
||||||
TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
|
|
||||||
DisableColors: true,
|
|
||||||
DisableTimestamp: false,
|
|
||||||
DisableSorting: false,
|
|
||||||
QuoteEmptyFields: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&dugong.DailyRotationSchedule{GZip: true},
|
&dugong.DailyRotationSchedule{GZip: true},
|
||||||
),
|
),
|
||||||
})
|
})*/
|
||||||
|
/// TODO: Dugong FSHook!
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloseAndLogIfError Closes io.Closer and logs the error if any
|
// CloseAndLogIfError Closes io.Closer and logs the error if any
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,10 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"log/syslog"
|
"os"
|
||||||
|
|
||||||
"github.com/MFAshby/stdemuxerhook"
|
"github.com/rs/zerolog"
|
||||||
"github.com/sirupsen/logrus"
|
log "github.com/rs/zerolog/log"
|
||||||
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
)
|
)
|
||||||
|
|
@ -31,20 +30,20 @@ import (
|
||||||
// SetupHookLogging configures the logging hooks defined in the configuration.
|
// SetupHookLogging configures the logging hooks defined in the configuration.
|
||||||
// If something fails here it means that the logging was improperly configured,
|
// If something fails here it means that the logging was improperly configured,
|
||||||
// so we just exit with the error
|
// so we just exit with the error
|
||||||
func SetupHookLogging(hooks []config.LogrusHook) {
|
func SetupHookLogging(hooks []config.LogHook) {
|
||||||
levelLogAddedMu.Lock()
|
levelLogAddedMu.Lock()
|
||||||
defer levelLogAddedMu.Unlock()
|
defer levelLogAddedMu.Unlock()
|
||||||
for _, hook := range hooks {
|
for _, hook := range hooks {
|
||||||
// Check we received a proper logging level
|
// Check we received a proper logging level
|
||||||
level, err := logrus.ParseLevel(hook.Level)
|
level, err := zerolog.ParseLevel(hook.Level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Unrecognised logging level %s: %q", hook.Level, err)
|
log.Fatal().Msgf("Unrecognised logging level %s: %q", hook.Level, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform a first filter on the logs according to the lowest level of all
|
// Perform a first filter on the logs according to the lowest level of all
|
||||||
// (Eg: If we have hook for info and above, prevent logrus from processing debug logs)
|
// (Eg: If we have hook for info and above, prevent logrus from processing debug logs)
|
||||||
if logrus.GetLevel() < level {
|
if log.Logger.GetLevel() < level {
|
||||||
logrus.SetLevel(level)
|
log.Logger = log.Logger.Level(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch hook.Type {
|
switch hook.Type {
|
||||||
|
|
@ -57,46 +56,50 @@ func SetupHookLogging(hooks []config.LogrusHook) {
|
||||||
case "std":
|
case "std":
|
||||||
setupStdLogHook(level)
|
setupStdLogHook(level)
|
||||||
default:
|
default:
|
||||||
logrus.Fatalf("Unrecognised logging hook type: %s", hook.Type)
|
log.Fatal().Msgf("Unrecognised logging hook type: %s", hook.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setupStdLogHook(logrus.InfoLevel)
|
setupStdLogHook(zerolog.InfoLevel)
|
||||||
// Hooks are now configured for stdout/err, so throw away the default logger output
|
// Hooks are now configured for stdout/err, so throw away the default logger output
|
||||||
logrus.SetOutput(io.Discard)
|
log.Logger = log.Logger.Output(io.Discard)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkSyslogHookParams(params map[string]interface{}) {
|
func checkSyslogHookParams(params map[string]interface{}) {
|
||||||
addr, ok := params["address"]
|
addr, ok := params["address"]
|
||||||
if !ok {
|
if !ok {
|
||||||
logrus.Fatalf("Expecting a parameter \"address\" for logging hook of type \"syslog\"")
|
log.Fatal().Msg("Expecting a parameter \"address\" for logging hook of type \"syslog\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := addr.(string); !ok {
|
if _, ok := addr.(string); !ok {
|
||||||
logrus.Fatalf("Parameter \"address\" for logging hook of type \"syslog\" should be a string")
|
log.Fatal().Msg("Parameter \"address\" for logging hook of type \"syslog\" should be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
proto, ok2 := params["protocol"]
|
proto, ok2 := params["protocol"]
|
||||||
if !ok2 {
|
if !ok2 {
|
||||||
logrus.Fatalf("Expecting a parameter \"protocol\" for logging hook of type \"syslog\"")
|
log.Fatal().Msg("Expecting a parameter \"protocol\" for logging hook of type \"syslog\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok2 := proto.(string); !ok2 {
|
if _, ok2 := proto.(string); !ok2 {
|
||||||
logrus.Fatalf("Parameter \"protocol\" for logging hook of type \"syslog\" should be a string")
|
log.Fatal().Msg("Parameter \"protocol\" for logging hook of type \"syslog\" should be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupStdLogHook(level logrus.Level) {
|
func setupStdLogHook(level zerolog.Level) {
|
||||||
if stdLevelLogAdded[level] {
|
if stdLevelLogAdded[level] {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.AddHook(&logLevelHook{level, stdemuxerhook.New(logrus.StandardLogger())})
|
//log.Logger.Hook(&logLevelHook{level, stdemuxerhook.New(log.Logger)})
|
||||||
|
//log.Logger.Hook(&logLevelHook{level, zerolog.New(os.Stdout)})
|
||||||
|
log.Logger = zerolog.New(os.Stdout)
|
||||||
stdLevelLogAdded[level] = true
|
stdLevelLogAdded[level] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupSyslogHook(hook config.LogrusHook, level logrus.Level) {
|
func setupSyslogHook(hook config.LogHook, level zerolog.Level) {
|
||||||
syslogHook, err := lSyslog.NewSyslogHook(hook.Params["protocol"].(string), hook.Params["address"].(string), syslog.LOG_INFO, "dendrite")
|
// rewrite to:
|
||||||
|
// https://stackoverflow.com/questions/73064915/logging-to-syslog-file-with-zerolog-golang
|
||||||
|
/*syslogHook, err := lSyslog.NewSyslogHook(hook.Params["protocol"].(string), hook.Params["address"].(string), syslog.LOG_INFO, "dendrite")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logrus.AddHook(&logLevelHook{level, syslogHook})
|
log.Logger.Hook(&logLevelHook{level, syslogHook})
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,18 @@ import (
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
"github.com/uber/jaeger-client-go"
|
||||||
jaegerconfig "github.com/uber/jaeger-client-go/config"
|
jaegerconfig "github.com/uber/jaeger-client-go/config"
|
||||||
jaegermetrics "github.com/uber/jaeger-lib/metrics"
|
jaegermetrics "github.com/uber/jaeger-lib/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var logger = zerolog.New(os.Stdout).With().Timestamp().Logger()
|
||||||
|
|
||||||
// keyIDRegexp defines allowable characters in Key IDs.
|
// keyIDRegexp defines allowable characters in Key IDs.
|
||||||
var keyIDRegexp = regexp.MustCompile("^ed25519:[a-zA-Z0-9_]+$")
|
var keyIDRegexp = regexp.MustCompile("^ed25519:[a-zA-Z0-9_]+$")
|
||||||
|
|
||||||
|
|
@ -74,8 +78,8 @@ type Dendrite struct {
|
||||||
Jaeger jaegerconfig.Configuration `yaml:"jaeger"`
|
Jaeger jaegerconfig.Configuration `yaml:"jaeger"`
|
||||||
} `yaml:"tracing"`
|
} `yaml:"tracing"`
|
||||||
|
|
||||||
// The config for logging informations. Each hook will be added to logrus.
|
// The config for logging informations. Each hook will be added.
|
||||||
Logging []LogrusHook `yaml:"logging"`
|
Logging []LogHook `yaml:"logging"`
|
||||||
|
|
||||||
// Any information derived from the configuration options for later use.
|
// Any information derived from the configuration options for later use.
|
||||||
Derived Derived `yaml:"-"`
|
Derived Derived `yaml:"-"`
|
||||||
|
|
@ -146,10 +150,10 @@ type ThumbnailSize struct {
|
||||||
ResizeMethod string `yaml:"method,omitempty"`
|
ResizeMethod string `yaml:"method,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogrusHook represents a single logrus hook. At this point, only parsing and
|
// LogHook represents a single log hook. At this point, only parsing and
|
||||||
// verification of the proper values for type and level are done.
|
// verification of the proper values for type and level are done.
|
||||||
// Validity/integrity checks on the parameters are done when configuring logrus.
|
// Validity/integrity checks on the parameters are done when configuring log.
|
||||||
type LogrusHook struct {
|
type LogHook struct {
|
||||||
// The type of hook, currently only "file" is supported.
|
// The type of hook, currently only "file" is supported.
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
|
|
||||||
|
|
@ -398,9 +402,9 @@ func checkPositive(configErrs *ConfigErrors, key string, value int64) {
|
||||||
|
|
||||||
// checkLogging verifies the parameters logging.* are valid.
|
// checkLogging verifies the parameters logging.* are valid.
|
||||||
func (config *Dendrite) checkLogging(configErrs *ConfigErrors) {
|
func (config *Dendrite) checkLogging(configErrs *ConfigErrors) {
|
||||||
for _, logrusHook := range config.Logging {
|
for _, logHook := range config.Logging {
|
||||||
checkNotEmpty(configErrs, "logging.type", string(logrusHook.Type))
|
checkNotEmpty(configErrs, "logging.type", string(logHook.Type))
|
||||||
checkNotEmpty(configErrs, "logging.level", string(logrusHook.Level))
|
checkNotEmpty(configErrs, "logging.level", string(logHook.Level))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -480,20 +484,31 @@ func (config *Dendrite) SetupTracing() (closer io.Closer, err error) {
|
||||||
}
|
}
|
||||||
return config.Tracing.Jaeger.InitGlobalTracer(
|
return config.Tracing.Jaeger.InitGlobalTracer(
|
||||||
"Dendrite",
|
"Dendrite",
|
||||||
jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}),
|
jaegerconfig.Logger(NewJaegerLogger(&logger)),
|
||||||
jaegerconfig.Metrics(jaegermetrics.NullFactory),
|
jaegerconfig.Metrics(jaegermetrics.NullFactory),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// logrusLogger is a small wrapper that implements jaeger.Logger using logrus.
|
type jaegerLogger struct {
|
||||||
type logrusLogger struct {
|
logger *zerolog.Logger
|
||||||
l *logrus.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logrusLogger) Error(msg string) {
|
func NewJaegerLogger(logger *zerolog.Logger) jaeger.Logger {
|
||||||
l.l.Error(msg)
|
return &jaegerLogger{logger}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logrusLogger) Infof(msg string, args ...interface{}) {
|
type Logger interface {
|
||||||
l.l.Infof(msg, args...)
|
// Error logs a message at error priority
|
||||||
|
Error(msg string)
|
||||||
|
|
||||||
|
// Infof logs a message at info priority
|
||||||
|
Infof(msg string, args ...interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (jl *jaegerLogger) Error(msg string) {
|
||||||
|
jl.logger.Error().Msg(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (jl *jaegerLogger) Infof(msg string, args ...interface{}) {
|
||||||
|
jl.logger.Info().Msgf(msg, args...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import (
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -30,6 +30,8 @@ var (
|
||||||
enableRegistrationWithoutVerification = flag.Bool("really-enable-open-registration", false, "This allows open registration without secondary verification (reCAPTCHA). This is NOT RECOMMENDED and will SIGNIFICANTLY increase the risk that your server will be used to send spam or conduct attacks, which may result in your server being banned from rooms.")
|
enableRegistrationWithoutVerification = flag.Bool("really-enable-open-registration", false, "This allows open registration without secondary verification (reCAPTCHA). This is NOT RECOMMENDED and will SIGNIFICANTLY increase the risk that your server will be used to send spam or conduct attacks, which may result in your server being banned from rooms.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var logger = zerolog.New(os.Stdout).With().Timestamp().Logger()
|
||||||
|
|
||||||
// ParseFlags parses the commandline flags and uses them to create a config.
|
// ParseFlags parses the commandline flags and uses them to create a config.
|
||||||
func ParseFlags(monolith bool) *config.Dendrite {
|
func ParseFlags(monolith bool) *config.Dendrite {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
@ -40,13 +42,13 @@ func ParseFlags(monolith bool) *config.Dendrite {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *configPath == "" {
|
if *configPath == "" {
|
||||||
logrus.Fatal("--config must be supplied")
|
logger.Fatal().Msg("--config must be supplied")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := config.Load(*configPath)
|
cfg, err := config.Load(*configPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Invalid config file: %s", err)
|
logger.Fatal().Msgf("Invalid config file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *enableRegistrationWithoutVerification {
|
if *enableRegistrationWithoutVerification {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue