logger_backend.go
TLDR
The file logger_backend.go
contains the code for the backend implementation of a notify logger. It provides methods for starting and shutting down the logger, handling block change events, and returning the name of the backend.
Methods
New(logger mlog.LoggerIFace, level mlog.Level) *Backend
This method creates a new instance of the Backend struct with the given logger and log level.
Start() error
This method starts the logger backend. It currently does nothing and always returns nil.
ShutDown() error
This method shuts down the logger backend. It flushes the logger and always returns nil.
BlockChanged(evt notify.BlockChangeEvent) error
This method handles block change events. It extracts relevant information from the event (such as action, board, card, and block ID) and logs them using the logger with the specified log level. It always returns nil.
Name() string
This method returns the name of the logger backend, which is "notifyLogger".
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package notifylogger
import (
"github.com/mattermost/focalboard/server/services/notify"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
const (
backendName = "notifyLogger"
)
type Backend struct {
logger mlog.LoggerIFace
level mlog.Level
}
func New(logger mlog.LoggerIFace, level mlog.Level) *Backend {
return &Backend{
logger: logger,
level: level,
}
}
func (b *Backend) Start() error {
return nil
}
func (b *Backend) ShutDown() error {
_ = b.logger.Flush()
return nil
}
func (b *Backend) BlockChanged(evt notify.BlockChangeEvent) error {
var board string
var card string
if evt.Board != nil {
board = evt.Board.Title
}
if evt.Card != nil {
card = evt.Card.Title
}
b.logger.Log(b.level, "Block change event",
mlog.String("action", string(evt.Action)),
mlog.String("board", board),
mlog.String("card", card),
mlog.String("block_id", evt.BlockChanged.ID),
)
return nil
}
func (b *Backend) Name() string {
return backendName
}