Update mautrix-go and switch to zerolog
This commit is contained in:
@@ -45,7 +45,7 @@ func (br *DiscordBridge) newDoublePuppetClient(mxid id.UserID, accessToken strin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client.Logger = br.AS.Log.Sub(mxid.String())
|
||||
client.Log = br.AS.Log.With().Str("as_user_id", mxid.String()).Logger()
|
||||
client.Client = br.AS.HTTPClient
|
||||
client.DefaultHTTPRetries = br.AS.DefaultHTTPRetries
|
||||
|
||||
|
||||
@@ -254,12 +254,15 @@ bridge:
|
||||
"example.com": user
|
||||
"@admin:example.com": admin
|
||||
|
||||
# Logging config. See https://github.com/tulir/zeroconfig for details.
|
||||
logging:
|
||||
directory: ./logs
|
||||
file_name_format: '{{.Date}}-{{.Index}}.log'
|
||||
file_date_format: "2006-01-02"
|
||||
file_mode: 384
|
||||
timestamp_format: Jan _2, 2006 15:04:05
|
||||
print_level: debug
|
||||
print_json: false
|
||||
file_json: false
|
||||
min_level: debug
|
||||
writers:
|
||||
- type: stdout
|
||||
format: pretty-colored
|
||||
- type: file
|
||||
format: json
|
||||
filename: ./logs/mautrix-discord.log
|
||||
max_size: 100
|
||||
max_backups: 10
|
||||
compress: true
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"github.com/yuin/goldmark/renderer"
|
||||
"github.com/yuin/goldmark/text"
|
||||
"github.com/yuin/goldmark/util"
|
||||
"maunium.net/go/mautrix"
|
||||
|
||||
"go.mau.fi/mautrix-discord/database"
|
||||
)
|
||||
@@ -305,7 +304,7 @@ func (r *discordTagHTMLRenderer) renderDiscordMention(w util.BufWriter, source [
|
||||
fullHumanReadable := ts.Format(discordTimestampStyle('F').Format())
|
||||
_, _ = fmt.Fprintf(w, `<time title="%s" datetime="%s"><strong>%s</strong></time>`, fullHumanReadable, fullRFC, formatted)
|
||||
}
|
||||
stringifiable, ok := n.(mautrix.Stringifiable)
|
||||
stringifiable, ok := n.(fmt.Stringer)
|
||||
if ok {
|
||||
_, _ = w.WriteString(stringifiable.String())
|
||||
} else {
|
||||
|
||||
9
go.mod
9
go.mod
@@ -10,26 +10,29 @@ require (
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/lib/pq v1.10.7
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
github.com/rs/zerolog v1.29.0
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/yuin/goldmark v1.5.4
|
||||
maunium.net/go/maulogger/v2 v2.3.2
|
||||
maunium.net/go/mautrix v0.14.0
|
||||
maunium.net/go/maulogger/v2 v2.4.1
|
||||
maunium.net/go/mautrix v0.15.0-beta.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rs/zerolog v1.29.0 // indirect
|
||||
github.com/tidwall/gjson v1.14.4 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/tidwall/sjson v1.2.5 // indirect
|
||||
go.mau.fi/zeroconfig v0.1.0 // indirect
|
||||
golang.org/x/crypto v0.6.0 // indirect
|
||||
golang.org/x/net v0.6.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
maunium.net/go/mauflag v1.0.0 // indirect
|
||||
)
|
||||
|
||||
13
go.sum
13
go.sum
@@ -1,6 +1,7 @@
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/beeper/discordgo v0.0.0-20230226184350-ef6bcfe94f07 h1:YajAt8iJkBn4aavUuftybeXUaeN4p0DPCE3a4wxE2Oc=
|
||||
github.com/beeper/discordgo v0.0.0-20230226184350-ef6bcfe94f07/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 h1:rtAn27wIbmOGUs7RIbVgPEjb31ehTVniDwPGXyMxm5U=
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
@@ -49,6 +50,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
|
||||
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mau.fi/zeroconfig v0.1.0 h1:SDGgreQevNJHb+QqGAs2Ff+OPXcGdO8rZencqP4BJi4=
|
||||
go.mau.fi/zeroconfig v0.1.0/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
@@ -70,12 +73,14 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
|
||||
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
||||
maunium.net/go/mautrix v0.14.0 h1:kdQ06HzmMaLGZqmSh/ykDhp5C2gIREQL9TS8hY+FqLs=
|
||||
maunium.net/go/mautrix v0.14.0/go.mod h1:voJPvnTkA60rxBl6mvdPxcP7y7iY5w3d/K55IoX+2oY=
|
||||
maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL8=
|
||||
maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho=
|
||||
maunium.net/go/mautrix v0.15.0-beta.1 h1:ISHvryI5ovYzsm5Tz/RQlDbohOoFiu0ymqL6VO4ucdI=
|
||||
maunium.net/go/mautrix v0.15.0-beta.1/go.mod h1:AE3TCX9q4W7fYfrL/1RsuOell9rTUBO27XUULuwArH4=
|
||||
|
||||
17
main.go
17
main.go
@@ -18,8 +18,13 @@ package main
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"maunium.net/go/mautrix/bridge"
|
||||
"maunium.net/go/mautrix/bridge/commands"
|
||||
"maunium.net/go/mautrix/id"
|
||||
@@ -93,7 +98,17 @@ func (br *DiscordBridge) Init() {
|
||||
br.RegisterCommands()
|
||||
|
||||
br.DB = database.New(br.Bridge.DB, br.Log.Sub("Database"))
|
||||
discordLog = br.Log.Sub("Discord")
|
||||
discordLog = br.ZLog.With().Str("component", "discordgo").Logger()
|
||||
|
||||
// TODO move this to mautrix-go?
|
||||
zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string {
|
||||
files := strings.Split(file, "/")
|
||||
file = files[len(files)-1]
|
||||
name := runtime.FuncForPC(pc).Name()
|
||||
fns := strings.Split(name, ".")
|
||||
name = fns[len(fns)-1]
|
||||
return fmt.Sprintf("%s:%d:%s()", file, line, name)
|
||||
}
|
||||
}
|
||||
|
||||
func (br *DiscordBridge) Start() {
|
||||
|
||||
30
user.go
30
user.go
@@ -6,7 +6,6 @@ import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/rs/zerolog"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
@@ -76,34 +76,22 @@ func (user *User) GetRemoteName() string {
|
||||
return user.DiscordID
|
||||
}
|
||||
|
||||
var discordLog log.Logger
|
||||
var discordLog zerolog.Logger
|
||||
|
||||
func init() {
|
||||
discordgo.Logger = func(msgL, caller int, format string, a ...interface{}) {
|
||||
pc, file, line, _ := runtime.Caller(caller + 1)
|
||||
|
||||
files := strings.Split(file, "/")
|
||||
file = files[len(files)-1]
|
||||
|
||||
name := runtime.FuncForPC(pc).Name()
|
||||
fns := strings.Split(name, ".")
|
||||
name = fns[len(fns)-1]
|
||||
|
||||
msg := fmt.Sprintf(format, a...)
|
||||
|
||||
var level log.Level
|
||||
var level zerolog.Level
|
||||
switch msgL {
|
||||
case discordgo.LogError:
|
||||
level = log.LevelError
|
||||
level = zerolog.ErrorLevel
|
||||
case discordgo.LogWarning:
|
||||
level = log.LevelWarn
|
||||
level = zerolog.WarnLevel
|
||||
case discordgo.LogInformational:
|
||||
level = log.LevelInfo
|
||||
level = zerolog.InfoLevel
|
||||
case discordgo.LogDebug:
|
||||
level = log.LevelDebug
|
||||
level = zerolog.DebugLevel
|
||||
}
|
||||
|
||||
discordLog.Logfln(level, "%s:%d:%s() %s", file, line, name, msg)
|
||||
discordLog.WithLevel(level).Caller(caller+1).Msgf(strings.TrimSpace(format), a...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +192,7 @@ func (br *DiscordBridge) NewUser(dbUser *database.User) *User {
|
||||
pendingInteractions: make(map[string]*WrappedCommandEvent),
|
||||
}
|
||||
user.nextDiscordUploadID.Store(rand.Int31n(100))
|
||||
user.BridgeState = br.NewBridgeStateQueue(user, user.log)
|
||||
user.BridgeState = br.NewBridgeStateQueue(user)
|
||||
return user
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user