Add optional syslog logrus hook (#343)

* add optional syslog logrus hook

* document syslog
This commit is contained in:
tobi 2021-12-12 18:00:20 +01:00 committed by GitHub
commit c111b239f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 2242 additions and 37 deletions

View file

@ -23,7 +23,6 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/log"
@ -52,12 +51,8 @@ func preRun(cmd *cobra.Command) error {
// The idea here is to take a GTSAction and run it with the given
// context, after initializing any last-minute things like loggers etc.
func run(ctx context.Context, action action.GTSAction) error {
// if log level has been set...
if logLevel := viper.GetString(config.Keys.LogLevel); logLevel != "" {
// then try to initialize the logger to that level
if err := log.Initialize(logLevel); err != nil {
return fmt.Errorf("error initializing log: %s", err)
}
if err := log.Initialize(); err != nil {
return fmt.Errorf("error initializing log: %s", err)
}
return action(ctx)

View file

@ -34,6 +34,7 @@ func Server(cmd *cobra.Command, values config.Values) {
OIDC(cmd, values)
SMTP(cmd, values)
Router(cmd, values)
Syslog(cmd, values)
}
// Router attaches flags pertaining to the gin router.
@ -109,3 +110,10 @@ func SMTP(cmd *cobra.Command, values config.Values) {
cmd.Flags().String(config.Keys.SMTPPassword, values.SMTPPassword, usage.SMTPPassword)
cmd.Flags().String(config.Keys.SMTPFrom, values.SMTPFrom, usage.SMTPFrom)
}
// Syslog attaches flags pertaining to syslog config.
func Syslog(cmd *cobra.Command, values config.Values) {
cmd.Flags().Bool(config.Keys.SyslogEnabled, values.SyslogEnabled, usage.SyslogEnabled)
cmd.Flags().String(config.Keys.SyslogProtocol, values.SyslogProtocol, usage.SyslogProtocol)
cmd.Flags().String(config.Keys.SyslogAddress, values.SyslogAddress, usage.SyslogAddress)
}

View file

@ -73,6 +73,9 @@ var usage = config.KeyNames{
SMTPUsername: "Username to authenticate with the smtp server as. Eg., 'postmaster@mail.example.org'",
SMTPPassword: "Password to pass to the smtp server.",
SMTPFrom: "Address to use as the 'from' field of the email. Eg., 'gotosocial@example.org'",
SyslogEnabled: "Enable the syslog logging hook. Logs will be mirrored to the configured destination.",
SyslogProtocol: "Protocol to use when directing logs to syslog. Leave empty to connect to local syslog.",
SyslogAddress: "Address:port to send syslog logs to. Leave empty to connect to local syslog.",
AdminAccountUsername: "the username to create/delete/etc",
AdminAccountEmail: "the email address of this account",
AdminAccountPassword: "the password to set for this account",