mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Adds Advanced Logging to server. Advanced Logging is an optional logging capability that allows customers to send log records to any number of destinations. Supported destinations: - file - syslog (with out without TLS) - raw TCP socket (with out without TLS) Allows developers to specify discrete log levels as well as the standard trace, debug, info, ... panic. Existing code and logging API usage is unchanged. Log records are emitted asynchronously to reduce latency to the caller. Supports hot-reloading of logger config, including adding removing targets. Advanced Logging is configured within config.json via "LogSettings.AdvancedLoggingConfig" which can contain a filespec to another config file, a database DSN, or JSON.
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
const (
|
|
validJSON = `{"file":{ "Type":"file"}}`
|
|
badJSON = `{"file":{ Type="file"}}`
|
|
)
|
|
|
|
type fgetFunc func(string) ([]byte, error)
|
|
|
|
func (f fgetFunc) GetFile(path string) ([]byte, error) {
|
|
return f(path)
|
|
}
|
|
|
|
func getValidFile(path string) ([]byte, error) {
|
|
return []byte(validJSON), nil
|
|
}
|
|
|
|
func getInvalidFile(path string) ([]byte, error) {
|
|
return nil, os.ErrNotExist
|
|
}
|
|
|
|
func TestNewLogConfigSrc(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dsn string
|
|
fget FileGetter
|
|
wantErr bool
|
|
wantType LogConfigSrc
|
|
}{
|
|
{name: "empty dsn", dsn: "", fget: fgetFunc(getInvalidFile), wantErr: true, wantType: nil},
|
|
{name: "garbage dsn", dsn: "!@wfejwcevioj", fget: fgetFunc(getInvalidFile), wantErr: true, wantType: nil},
|
|
{name: "valid json dsn", dsn: validJSON, fget: fgetFunc(getInvalidFile), wantErr: false, wantType: &jsonSrc{}},
|
|
{name: "invalid json dsn", dsn: badJSON, fget: fgetFunc(getInvalidFile), wantErr: true, wantType: nil},
|
|
{name: "valid filespec dsn", dsn: "advancedlogging.conf", fget: fgetFunc(getValidFile), wantErr: false, wantType: &fileSrc{}},
|
|
{name: "invalid filespec dsn", dsn: "/nobody/here.conf", fget: fgetFunc(getInvalidFile), wantErr: true, wantType: nil},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NewLogConfigSrc(tt.dsn, IsJsonMap(tt.dsn), tt.fget)
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.IsType(t, tt.wantType, got)
|
|
}
|
|
})
|
|
}
|
|
}
|