Documentation
¶
Index ¶
- Constants
- func Err(err error) slog.Attr
- func Fatal(logger *slog.Logger, msg string, args ...any)
- func NewConfig(prefix string) (*viper.Viper, error)
- func NewLogger(config *viper.Viper) (*slog.Logger, error)
- func NewMetricsInvoke(ms *Multiserver) error
- func NewNopLogger() *slog.Logger
- func NewProfilerInvoke(ms *Multiserver) error
- func NewSentryInvoke(config *viper.Viper, lc fx.Lifecycle) error
- func WithHealthcheck(path string) serverOption
- type Healthchecker
- type Multiserver
- type Narada
- type Options
- type SentryHandler
- type SlackAttachment
- type SlackClient
- type SlackError
- type SlackField
- type SlackHandler
- type SlackMessage
Constants ¶
const ErrorKey = "error"
ErrorKey is the attribute key narada uses to carry an error on a log record. The Sentry and Slack handlers look for it to report the underlying error instead of synthesising one from the message.
Variables ¶
This section is empty.
Functions ¶
func Err ¶
Err wraps err as a log attribute under ErrorKey. It is the slog replacement for logrus' WithError.
func Fatal ¶
Fatal logs at error level and terminates the process, replacing logrus' Fatal. slog has no fatal level, so the record is emitted at slog.LevelError; Sentry is flushed first so the report survives the exit.
func NewConfig ¶
NewConfig creates a new configuration, by default config file will be `config.yml` in same directory you run application if you want to override it you should provide `NARADA_CONFIG` environment variable.
func NewLogger ¶
NewLogger builds the application logger from configuration.
The handler chain is Slack -> Sentry (optional) -> text/json writer, so an error record reaches both sinks and is still written to stderr.
func NewMetricsInvoke ¶
func NewMetricsInvoke(ms *Multiserver) error
func NewNopLogger ¶
NewNopLogger returns a logger that discards every record.
func NewProfilerInvoke ¶
func NewProfilerInvoke(ms *Multiserver) error
func WithHealthcheck ¶
func WithHealthcheck(path string) serverOption
Types ¶
type Healthchecker ¶
type Healthchecker func() error
type Multiserver ¶
type Multiserver struct {
// contains filtered or unexported fields
}
func NewMultiServers ¶
func (*Multiserver) Add ¶
func (ms *Multiserver) Add(name string, handler http.Handler, opts ...serverOption) error
func (*Multiserver) AddHealthcheck ¶
func (ms *Multiserver) AddHealthcheck(name, path string, check Healthchecker) error
type Narada ¶
type Narada struct {
// contains filtered or unexported fields
}
func (Narada) HandleError ¶
type SentryHandler ¶
type SentryHandler struct {
// contains filtered or unexported fields
}
SentryHandler reports error-level records to Sentry and forwards every record to the next handler.
func NewSentryHandler ¶
func NewSentryHandler(next slog.Handler) *SentryHandler
type SlackAttachment ¶
type SlackAttachment struct {
Title string `json:"title"`
Fallback string `json:"fallback"`
Text string `json:"text"`
Pretext string `json:"pretext"`
Color string `json:"color"`
Fields []*SlackField `json:"fields"`
}
func NewAttachment ¶
func NewAttachment() *SlackAttachment
func (*SlackAttachment) AddField ¶
func (a *SlackAttachment) AddField(f *SlackField)
type SlackClient ¶
type SlackClient struct {
Url string
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(url string) *SlackClient
func (*SlackClient) SendMessage ¶
func (c *SlackClient) SendMessage(msg *SlackMessage) error
type SlackError ¶
func (*SlackError) Error ¶
func (e *SlackError) Error() string
type SlackField ¶
type SlackField struct {
Title string `json:"title"`
Value string `json:"value"`
Short bool `json:"short"`
}
func NewField ¶
func NewField() *SlackField
type SlackHandler ¶
type SlackHandler struct {
// contains filtered or unexported fields
}
SlackHandler posts error-level records to a Slack webhook and forwards every record to the next handler.
func NewSlackHandler ¶
func NewSlackHandler(config *viper.Viper, next slog.Handler) *SlackHandler
type SlackMessage ¶
type SlackMessage struct {
Text string `json:"text"`
Username string `json:"username"`
IconUrl string `json:"icon_url"`
IconEmoji string `json:"icon_emoji"`
Channel string `json:"channel"`
UnfurlLinks bool `json:"unfurl_links"`
Attachments []*SlackAttachment `json:"attachments"`
}
func (*SlackMessage) AddAttachment ¶
func (m *SlackMessage) AddAttachment(a *SlackAttachment)