Merge branch 'main' into 1416_reminders
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
commit
06548195ce
|
@ -168,6 +168,10 @@ log:
|
||||||
events: "off"
|
events: "off"
|
||||||
# The log level for event log messages. Possible values (case-insensitive) are ERROR, INFO, DEBUG.
|
# The log level for event log messages. Possible values (case-insensitive) are ERROR, INFO, DEBUG.
|
||||||
eventslevel: "info"
|
eventslevel: "info"
|
||||||
|
# Whether or not to log mail log messages. This will not log mail contents. Possible values are stdout, stderr, file or off to disable mail-related logging.
|
||||||
|
mail: "off"
|
||||||
|
# The log level for mail log messages. Possible values (case-insensitive) are ERROR, WARNING, INFO, DEBUG.
|
||||||
|
maillevel: "info"
|
||||||
|
|
||||||
ratelimit:
|
ratelimit:
|
||||||
# whether or not to enable the rate limit
|
# whether or not to enable the rate limit
|
||||||
|
|
|
@ -871,6 +871,28 @@ Full path: `log.eventslevel`
|
||||||
Environment path: `VIKUNJA_LOG_EVENTSLEVEL`
|
Environment path: `VIKUNJA_LOG_EVENTSLEVEL`
|
||||||
|
|
||||||
|
|
||||||
|
### mail
|
||||||
|
|
||||||
|
Whether or not to log mail log messages. This will not log mail contents. Possible values are stdout, stderr, file or off to disable mail-related logging.
|
||||||
|
|
||||||
|
Default: `off`
|
||||||
|
|
||||||
|
Full path: `log.mail`
|
||||||
|
|
||||||
|
Environment path: `VIKUNJA_LOG_MAIL`
|
||||||
|
|
||||||
|
|
||||||
|
### maillevel
|
||||||
|
|
||||||
|
The log level for mail log messages. Possible values (case-insensitive) are ERROR, WARNING, INFO, DEBUG.
|
||||||
|
|
||||||
|
Default: `info`
|
||||||
|
|
||||||
|
Full path: `log.maillevel`
|
||||||
|
|
||||||
|
Environment path: `VIKUNJA_LOG_MAILLEVEL`
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ratelimit
|
## ratelimit
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -62,7 +62,7 @@ require (
|
||||||
github.com/tkuchiki/go-timezone v0.2.2
|
github.com/tkuchiki/go-timezone v0.2.2
|
||||||
github.com/ulule/limiter/v3 v3.11.1
|
github.com/ulule/limiter/v3 v3.11.1
|
||||||
github.com/vectordotdev/go-datemath v0.1.1-0.20220323213446-f3954d0b18ae
|
github.com/vectordotdev/go-datemath v0.1.1-0.20220323213446-f3954d0b18ae
|
||||||
github.com/wneessen/go-mail v0.3.8
|
github.com/wneessen/go-mail v0.3.9
|
||||||
github.com/yuin/goldmark v1.5.4
|
github.com/yuin/goldmark v1.5.4
|
||||||
golang.org/x/crypto v0.7.0
|
golang.org/x/crypto v0.7.0
|
||||||
golang.org/x/image v0.6.0
|
golang.org/x/image v0.6.0
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -719,6 +719,8 @@ github.com/vectordotdev/go-datemath v0.1.1-0.20220323213446-f3954d0b18ae h1:oyiy
|
||||||
github.com/vectordotdev/go-datemath v0.1.1-0.20220323213446-f3954d0b18ae/go.mod h1:PnwzbSst7KD3vpBzzlntZU5gjVa455Uqa5QPiKSYJzQ=
|
github.com/vectordotdev/go-datemath v0.1.1-0.20220323213446-f3954d0b18ae/go.mod h1:PnwzbSst7KD3vpBzzlntZU5gjVa455Uqa5QPiKSYJzQ=
|
||||||
github.com/wneessen/go-mail v0.3.8 h1:ja5D/o/RVwrtRIYFlrO7GmtcjDNeMakGQuwQRZYv0JM=
|
github.com/wneessen/go-mail v0.3.8 h1:ja5D/o/RVwrtRIYFlrO7GmtcjDNeMakGQuwQRZYv0JM=
|
||||||
github.com/wneessen/go-mail v0.3.8/go.mod h1:m25lkU2GYQnlVr6tdwK533/UXxo57V0kLOjaFYmub0E=
|
github.com/wneessen/go-mail v0.3.8/go.mod h1:m25lkU2GYQnlVr6tdwK533/UXxo57V0kLOjaFYmub0E=
|
||||||
|
github.com/wneessen/go-mail v0.3.9 h1:Q4DbCk3htT5DtDWKeMgNXCiHc4bBY/vv/XQPT6XDXzc=
|
||||||
|
github.com/wneessen/go-mail v0.3.9/go.mod h1:zxOlafWCP/r6FEhAaRgH4IC1vg2YXxO0Nar9u0IScZ8=
|
||||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
|
|
@ -118,6 +118,8 @@ const (
|
||||||
LogPath Key = `log.path`
|
LogPath Key = `log.path`
|
||||||
LogEvents Key = `log.events`
|
LogEvents Key = `log.events`
|
||||||
LogEventsLevel Key = `log.eventslevel`
|
LogEventsLevel Key = `log.eventslevel`
|
||||||
|
LogMail Key = `log.mail`
|
||||||
|
LogMailLevel Key = `log.maillevel`
|
||||||
|
|
||||||
RateLimitEnabled Key = `ratelimit.enabled`
|
RateLimitEnabled Key = `ratelimit.enabled`
|
||||||
RateLimitKind Key = `ratelimit.kind`
|
RateLimitKind Key = `ratelimit.kind`
|
||||||
|
@ -351,6 +353,8 @@ func InitDefaultConfig() {
|
||||||
LogPath.setDefault(ServiceRootpath.GetString() + "/logs")
|
LogPath.setDefault(ServiceRootpath.GetString() + "/logs")
|
||||||
LogEvents.setDefault("off")
|
LogEvents.setDefault("off")
|
||||||
LogEventsLevel.setDefault("INFO")
|
LogEventsLevel.setDefault("INFO")
|
||||||
|
LogMail.setDefault("off")
|
||||||
|
LogMailLevel.setDefault("INFO")
|
||||||
// Rate Limit
|
// Rate Limit
|
||||||
RateLimitEnabled.setDefault(false)
|
RateLimitEnabled.setDefault(false)
|
||||||
RateLimitKind.setDefault("user")
|
RateLimitKind.setDefault("user")
|
||||||
|
|
87
pkg/log/mail_logger.go
Normal file
87
pkg/log/mail_logger.go
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
// Vikunja is a to-do list application to facilitate your life.
|
||||||
|
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public Licensee as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public Licensee for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public Licensee
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"github.com/op/go-logging"
|
||||||
|
"xorm.io/xorm/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MailLogger struct {
|
||||||
|
logger *logging.Logger
|
||||||
|
level log.LogLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
const mailFormat = `%{color}%{time:` + time.RFC3339Nano + `}: %{level}` + "\t" + `▶ [MAIL] %{id:03x}%{color:reset} %{message}`
|
||||||
|
const mailLogModule = `vikunja_mail`
|
||||||
|
|
||||||
|
func NewMailLogger() *MailLogger {
|
||||||
|
lvl := strings.ToUpper(config.LogMailLevel.GetString())
|
||||||
|
level, err := logging.LogLevel(lvl)
|
||||||
|
if err != nil {
|
||||||
|
Criticalf("Error setting database log level: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
mailLogger := &MailLogger{
|
||||||
|
logger: logging.MustGetLogger(mailLogModule),
|
||||||
|
}
|
||||||
|
|
||||||
|
logBackend := logging.NewLogBackend(GetLogWriter("mail"), "", 0)
|
||||||
|
backend := logging.NewBackendFormatter(logBackend, logging.MustStringFormatter(mailFormat+"\n"))
|
||||||
|
|
||||||
|
backendLeveled := logging.AddModuleLevel(backend)
|
||||||
|
backendLeveled.SetLevel(level, mailLogModule)
|
||||||
|
|
||||||
|
mailLogger.logger.SetBackend(backendLeveled)
|
||||||
|
|
||||||
|
switch level {
|
||||||
|
case logging.CRITICAL:
|
||||||
|
case logging.ERROR:
|
||||||
|
mailLogger.level = log.LOG_ERR
|
||||||
|
case logging.WARNING:
|
||||||
|
mailLogger.level = log.LOG_WARNING
|
||||||
|
case logging.NOTICE:
|
||||||
|
case logging.INFO:
|
||||||
|
mailLogger.level = log.LOG_INFO
|
||||||
|
case logging.DEBUG:
|
||||||
|
mailLogger.level = log.LOG_DEBUG
|
||||||
|
default:
|
||||||
|
mailLogger.level = log.LOG_OFF
|
||||||
|
}
|
||||||
|
|
||||||
|
return mailLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MailLogger) Errorf(format string, v ...interface{}) {
|
||||||
|
m.logger.Errorf(format, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MailLogger) Warnf(format string, v ...interface{}) {
|
||||||
|
m.logger.Warningf(format, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MailLogger) Infof(format string, v ...interface{}) {
|
||||||
|
m.logger.Infof(format, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MailLogger) Debugf(format string, v ...interface{}) {
|
||||||
|
m.logger.Debugf(format, v...)
|
||||||
|
}
|
|
@ -56,6 +56,8 @@ func getClient() (*mail.Client, error) {
|
||||||
ServerName: config.MailerHost.GetString(),
|
ServerName: config.MailerHost.GetString(),
|
||||||
}),
|
}),
|
||||||
mail.WithTimeout((config.MailerQueueTimeout.GetDuration() + 3) * time.Second), // 3s more for us to close before mail server timeout
|
mail.WithTimeout((config.MailerQueueTimeout.GetDuration() + 3) * time.Second), // 3s more for us to close before mail server timeout
|
||||||
|
mail.WithLogger(log.NewMailLogger()),
|
||||||
|
mail.WithDebugLog(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.MailerForceSSL.GetBool() {
|
if config.MailerForceSSL.GetBool() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user