5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-12-28 17:05:39 +00:00
matterbridge/vendor/github.com/mattermost/ldap/debug.go

50 lines
929 B
Go
Raw Normal View History

2020-08-09 22:29:54 +00:00
package ldap
import (
"bytes"
ber "github.com/go-asn1-ber/asn1-ber"
"github.com/mattermost/mattermost/server/public/shared/mlog"
2020-08-09 22:29:54 +00:00
)
type debugging struct {
logger mlog.LoggerIFace
levels []mlog.Level
}
2020-08-09 22:29:54 +00:00
// Enable controls debugging mode.
func (debug *debugging) Enable(logger mlog.LoggerIFace, levels ...mlog.Level) {
*debug = debugging{
logger: logger,
levels: levels,
}
}
func (debug debugging) Enabled() bool {
return debug.logger != nil
2020-08-09 22:29:54 +00:00
}
// Log writes debug output.
func (debug debugging) Log(msg string, fields ...mlog.Field) {
if debug.Enabled() {
debug.logger.LogM(debug.levels, msg, fields...)
2020-08-09 22:29:54 +00:00
}
}
type Packet ber.Packet
func (p Packet) LogClone() any {
bp := ber.Packet(p)
var b bytes.Buffer
ber.WritePacket(&b, &bp)
return b.String()
}
func PacketToField(packet *ber.Packet) mlog.Field {
if packet == nil {
return mlog.Any("packet", nil)
2020-08-09 22:29:54 +00:00
}
return mlog.Any("packet", Packet(*packet))
2020-08-09 22:29:54 +00:00
}