Adding upstream version 0.8.9.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
3b2c48b5e4
commit
c0c4addb85
285 changed files with 25880 additions and 0 deletions
61
pkg/services/logger/logger.go
Normal file
61
pkg/services/logger/logger.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/nicholas-fedor/shoutrrr/pkg/services/standard"
|
||||
"github.com/nicholas-fedor/shoutrrr/pkg/types"
|
||||
)
|
||||
|
||||
// Service is the Logger service struct.
|
||||
type Service struct {
|
||||
standard.Standard
|
||||
Config *Config
|
||||
}
|
||||
|
||||
// Send a notification message to log.
|
||||
func (service *Service) Send(message string, params *types.Params) error {
|
||||
data := types.Params{}
|
||||
|
||||
if params != nil {
|
||||
for key, value := range *params {
|
||||
data[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
data["message"] = message
|
||||
|
||||
return service.doSend(data)
|
||||
}
|
||||
|
||||
func (service *Service) doSend(data types.Params) error {
|
||||
msg := data["message"]
|
||||
|
||||
if tpl, found := service.GetTemplate("message"); found {
|
||||
wc := &strings.Builder{}
|
||||
if err := tpl.Execute(wc, data); err != nil {
|
||||
return fmt.Errorf("failed to write template to log: %w", err)
|
||||
}
|
||||
|
||||
msg = wc.String()
|
||||
}
|
||||
|
||||
service.Log(msg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Initialize loads ServiceConfig from configURL and sets logger for this Service.
|
||||
func (service *Service) Initialize(_ *url.URL, logger types.StdLogger) error {
|
||||
service.SetLogger(logger)
|
||||
service.Config = &Config{}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetID returns the service identifier.
|
||||
func (service *Service) GetID() string {
|
||||
return Scheme
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue