config/logger: remove syslogger and upgrade to config v10 which eliminates syslog config (#3336)

This commit is contained in:
Anis Elleuch 2016-11-24 00:00:53 +01:00 committed by Harshavardhana
parent f4f512fedd
commit 14cb3645a3
10 changed files with 190 additions and 190 deletions

View File

@ -58,6 +58,10 @@ func migrateConfig() error {
if err := migrateV8ToV9(); err != nil { if err := migrateV8ToV9(); err != nil {
return err return err
} }
// Migrate version '9' to '10'.
if err := migrateV9ToV10(); err != nil {
return err
}
return nil return nil
} }
@ -124,7 +128,7 @@ func migrateV2ToV3() error {
} }
srvConfig.Logger.File = flogger srvConfig.Logger.File = flogger
slogger := syslogLogger{} slogger := syslogLoggerV3{}
slogger.Level = "debug" slogger.Level = "debug"
if cv2.SyslogLogger.Addr != "" { if cv2.SyslogLogger.Addr != "" {
slogger.Enable = true slogger.Enable = true
@ -543,3 +547,88 @@ func migrateV8ToV9() error {
) )
return nil return nil
} }
// Version '9' to '10' migration. Remove syslog config
// but it's otherwise the same as V9.
func migrateV9ToV10() error {
cv9, err := loadConfigV9()
if err != nil {
if os.IsNotExist(err) {
return nil
}
return fmt.Errorf("Unable to load config version 9. %v", err)
}
if cv9.Version != "9" {
return nil
}
// Copy over fields from V9 into V10 config struct
srvConfig := &serverConfigV10{}
srvConfig.Version = "10"
srvConfig.Credential = cv9.Credential
srvConfig.Region = cv9.Region
if srvConfig.Region == "" {
// Region needs to be set for AWS Signature Version 4.
srvConfig.Region = "us-east-1"
}
srvConfig.Logger.Console = cv9.Logger.Console
srvConfig.Logger.File = cv9.Logger.File
// check and set notifiers config
if len(cv9.Notify.AMQP) == 0 {
srvConfig.Notify.AMQP = make(map[string]amqpNotify)
srvConfig.Notify.AMQP["1"] = amqpNotify{}
} else {
srvConfig.Notify.AMQP = cv9.Notify.AMQP
}
if len(cv9.Notify.NATS) == 0 {
srvConfig.Notify.NATS = make(map[string]natsNotify)
srvConfig.Notify.NATS["1"] = natsNotify{}
} else {
srvConfig.Notify.NATS = cv9.Notify.NATS
}
if len(cv9.Notify.ElasticSearch) == 0 {
srvConfig.Notify.ElasticSearch = make(map[string]elasticSearchNotify)
srvConfig.Notify.ElasticSearch["1"] = elasticSearchNotify{}
} else {
srvConfig.Notify.ElasticSearch = cv9.Notify.ElasticSearch
}
if len(cv9.Notify.Redis) == 0 {
srvConfig.Notify.Redis = make(map[string]redisNotify)
srvConfig.Notify.Redis["1"] = redisNotify{}
} else {
srvConfig.Notify.Redis = cv9.Notify.Redis
}
if len(cv9.Notify.PostgreSQL) == 0 {
srvConfig.Notify.PostgreSQL = make(map[string]postgreSQLNotify)
srvConfig.Notify.PostgreSQL["1"] = postgreSQLNotify{}
} else {
srvConfig.Notify.PostgreSQL = cv9.Notify.PostgreSQL
}
qc, err := quick.New(srvConfig)
if err != nil {
return fmt.Errorf("Unable to initialize the quick config. %v",
err)
}
configFile, err := getConfigFile()
if err != nil {
return fmt.Errorf("Unable to get config file. %v", err)
}
err = qc.Save(configFile)
if err != nil {
return fmt.Errorf(
"Failed to migrate config from "+
cv9.Version+" to "+srvConfig.Version+
" failed. %v", err,
)
}
console.Println(
"Migration from version " +
cv9.Version + " to " + srvConfig.Version +
" completed successfully.",
)
return nil
}

View File

@ -19,12 +19,9 @@ package cmd
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"strconv"
"testing" "testing"
) )
const lastConfigVersion = 9
// Test if config v1 is purged // Test if config v1 is purged
func TestServerConfigMigrateV1(t *testing.T) { func TestServerConfigMigrateV1(t *testing.T) {
rootPath, err := newTestConfig("us-east-1") rootPath, err := newTestConfig("us-east-1")
@ -97,10 +94,13 @@ func TestServerConfigMigrateInexistentConfig(t *testing.T) {
if err := migrateV8ToV9(); err != nil { if err := migrateV8ToV9(); err != nil {
t.Fatal("migrate v8 to v9 should succeed when no config file is found") t.Fatal("migrate v8 to v9 should succeed when no config file is found")
} }
if err := migrateV9ToV10(); err != nil {
t.Fatal("migrate v9 to v10 should succeed when no config file is found")
}
} }
// Test if a config migration from v2 to v9 is successfully done // Test if a config migration from v2 to v10 is successfully done
func TestServerConfigMigrateV2toV9(t *testing.T) { func TestServerConfigMigrateV2toV10(t *testing.T) {
rootPath, err := newTestConfig("us-east-1") rootPath, err := newTestConfig("us-east-1")
if err != nil { if err != nil {
t.Fatalf("Init Test config failed") t.Fatalf("Init Test config failed")
@ -139,7 +139,7 @@ func TestServerConfigMigrateV2toV9(t *testing.T) {
} }
// Check the version number in the upgraded config file // Check the version number in the upgraded config file
expectedVersion := strconv.Itoa(lastConfigVersion) expectedVersion := globalMinioConfigVersion
if serverConfig.Version != expectedVersion { if serverConfig.Version != expectedVersion {
t.Fatalf("Expect version "+expectedVersion+", found: %v", serverConfig.Version) t.Fatalf("Expect version "+expectedVersion+", found: %v", serverConfig.Version)
} }
@ -197,4 +197,7 @@ func TestServerConfigMigrateFaultyConfig(t *testing.T) {
if err := migrateV8ToV9(); err == nil { if err := migrateV8ToV9(); err == nil {
t.Fatal("migrateConfigV8ToV9() should fail with a corrupted json") t.Fatal("migrateConfigV8ToV9() should fail with a corrupted json")
} }
if err := migrateV9ToV10(); err == nil {
t.Fatal("migrateConfigV9ToV10() should fail with a corrupted json")
}
} }

View File

@ -89,6 +89,13 @@ type backendV3 struct {
Disks []string `json:"disks,omitempty"` Disks []string `json:"disks,omitempty"`
} }
// syslogLogger v3
type syslogLoggerV3 struct {
Enable bool `json:"enable"`
Addr string `json:"address"`
Level string `json:"level"`
}
// loggerV3 type. // loggerV3 type.
type loggerV3 struct { type loggerV3 struct {
Console struct { Console struct {
@ -276,6 +283,12 @@ func loadConfigV5() (*configV5, error) {
return c, nil return c, nil
} }
type loggerV6 struct {
Console consoleLogger `json:"console"`
File fileLogger `json:"file"`
Syslog syslogLoggerV3 `json:"syslog"`
}
// configV6 server configuration version '6'. // configV6 server configuration version '6'.
type configV6 struct { type configV6 struct {
Version string `json:"version"` Version string `json:"version"`
@ -285,7 +298,7 @@ type configV6 struct {
Region string `json:"region"` Region string `json:"region"`
// Additional error logging configuration. // Additional error logging configuration.
Logger logger `json:"logger"` Logger loggerV6 `json:"logger"`
// Notification queue configuration. // Notification queue configuration.
Notify notifier `json:"notify"` Notify notifier `json:"notify"`
@ -321,7 +334,7 @@ type serverConfigV7 struct {
Region string `json:"region"` Region string `json:"region"`
// Additional error logging configuration. // Additional error logging configuration.
Logger logger `json:"logger"` Logger loggerV6 `json:"logger"`
// Notification queue configuration. // Notification queue configuration.
Notify notifier `json:"notify"` Notify notifier `json:"notify"`
@ -361,7 +374,7 @@ type serverConfigV8 struct {
Region string `json:"region"` Region string `json:"region"`
// Additional error logging configuration. // Additional error logging configuration.
Logger logger `json:"logger"` Logger loggerV6 `json:"logger"`
// Notification queue configuration. // Notification queue configuration.
Notify notifier `json:"notify"` Notify notifier `json:"notify"`
@ -390,3 +403,46 @@ func loadConfigV8() (*serverConfigV8, error) {
} }
return c, nil return c, nil
} }
// serverConfigV9 server configuration version '9'. Adds PostgreSQL
// notifier configuration.
type serverConfigV9 struct {
Version string `json:"version"`
// S3 API configuration.
Credential credential `json:"credential"`
Region string `json:"region"`
// Additional error logging configuration.
Logger loggerV6 `json:"logger"`
// Notification queue configuration.
Notify notifier `json:"notify"`
// Read Write mutex.
rwMutex *sync.RWMutex
}
func loadConfigV9() (*serverConfigV9, error) {
configFile, err := getConfigFile()
if err != nil {
return nil, err
}
if _, err = os.Stat(configFile); err != nil {
return nil, err
}
srvCfg := &serverConfigV9{}
srvCfg.Version = "9"
srvCfg.rwMutex = &sync.RWMutex{}
qc, err := quick.New(srvCfg)
if err != nil {
return nil, err
}
if err := qc.Load(configFile); err != nil {
return nil, err
}
// Set the version properly after the unmarshalled json is loaded.
srvCfg.Version = "9"
return srvCfg, nil
}

View File

@ -23,9 +23,9 @@ import (
"github.com/minio/minio/pkg/quick" "github.com/minio/minio/pkg/quick"
) )
// serverConfigV9 server configuration version '9'. Adds PostgreSQL // serverConfigV10 server configuration version '10' which is like version '9'
// notifier configuration. // except it drops support of syslog config
type serverConfigV9 struct { type serverConfigV10 struct {
Version string `json:"version"` Version string `json:"version"`
// S3 API configuration. // S3 API configuration.
@ -46,7 +46,7 @@ type serverConfigV9 struct {
func initConfig() (bool, error) { func initConfig() (bool, error) {
if !isConfigFileExists() { if !isConfigFileExists() {
// Initialize server config. // Initialize server config.
srvCfg := &serverConfigV9{} srvCfg := &serverConfigV10{}
srvCfg.Version = globalMinioConfigVersion srvCfg.Version = globalMinioConfigVersion
srvCfg.Region = "us-east-1" srvCfg.Region = "us-east-1"
srvCfg.Credential = mustGenAccessKeys() srvCfg.Credential = mustGenAccessKeys()
@ -89,7 +89,7 @@ func initConfig() (bool, error) {
if _, err = os.Stat(configFile); err != nil { if _, err = os.Stat(configFile); err != nil {
return false, err return false, err
} }
srvCfg := &serverConfigV9{} srvCfg := &serverConfigV10{}
srvCfg.Version = globalMinioConfigVersion srvCfg.Version = globalMinioConfigVersion
srvCfg.rwMutex = &sync.RWMutex{} srvCfg.rwMutex = &sync.RWMutex{}
qc, err := quick.New(srvCfg) qc, err := quick.New(srvCfg)
@ -108,10 +108,10 @@ func initConfig() (bool, error) {
} }
// serverConfig server config. // serverConfig server config.
var serverConfig *serverConfigV9 var serverConfig *serverConfigV10
// GetVersion get current config version. // GetVersion get current config version.
func (s serverConfigV9) GetVersion() string { func (s serverConfigV10) GetVersion() string {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Version return s.Version
@ -119,173 +119,159 @@ func (s serverConfigV9) GetVersion() string {
/// Logger related. /// Logger related.
func (s *serverConfigV9) SetAMQPNotifyByID(accountID string, amqpn amqpNotify) { func (s *serverConfigV10) SetAMQPNotifyByID(accountID string, amqpn amqpNotify) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Notify.AMQP[accountID] = amqpn s.Notify.AMQP[accountID] = amqpn
} }
func (s serverConfigV9) GetAMQP() map[string]amqpNotify { func (s serverConfigV10) GetAMQP() map[string]amqpNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.AMQP return s.Notify.AMQP
} }
// GetAMQPNotify get current AMQP logger. // GetAMQPNotify get current AMQP logger.
func (s serverConfigV9) GetAMQPNotifyByID(accountID string) amqpNotify { func (s serverConfigV10) GetAMQPNotifyByID(accountID string) amqpNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.AMQP[accountID] return s.Notify.AMQP[accountID]
} }
// //
func (s *serverConfigV9) SetNATSNotifyByID(accountID string, natsn natsNotify) { func (s *serverConfigV10) SetNATSNotifyByID(accountID string, natsn natsNotify) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Notify.NATS[accountID] = natsn s.Notify.NATS[accountID] = natsn
} }
func (s serverConfigV9) GetNATS() map[string]natsNotify { func (s serverConfigV10) GetNATS() map[string]natsNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.NATS return s.Notify.NATS
} }
// GetNATSNotify get current NATS logger. // GetNATSNotify get current NATS logger.
func (s serverConfigV9) GetNATSNotifyByID(accountID string) natsNotify { func (s serverConfigV10) GetNATSNotifyByID(accountID string) natsNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.NATS[accountID] return s.Notify.NATS[accountID]
} }
func (s *serverConfigV9) SetElasticSearchNotifyByID(accountID string, esNotify elasticSearchNotify) { func (s *serverConfigV10) SetElasticSearchNotifyByID(accountID string, esNotify elasticSearchNotify) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Notify.ElasticSearch[accountID] = esNotify s.Notify.ElasticSearch[accountID] = esNotify
} }
func (s serverConfigV9) GetElasticSearch() map[string]elasticSearchNotify { func (s serverConfigV10) GetElasticSearch() map[string]elasticSearchNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.ElasticSearch return s.Notify.ElasticSearch
} }
// GetElasticSearchNotify get current ElasicSearch logger. // GetElasticSearchNotify get current ElasicSearch logger.
func (s serverConfigV9) GetElasticSearchNotifyByID(accountID string) elasticSearchNotify { func (s serverConfigV10) GetElasticSearchNotifyByID(accountID string) elasticSearchNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.ElasticSearch[accountID] return s.Notify.ElasticSearch[accountID]
} }
func (s *serverConfigV9) SetRedisNotifyByID(accountID string, rNotify redisNotify) { func (s *serverConfigV10) SetRedisNotifyByID(accountID string, rNotify redisNotify) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Notify.Redis[accountID] = rNotify s.Notify.Redis[accountID] = rNotify
} }
func (s serverConfigV9) GetRedis() map[string]redisNotify { func (s serverConfigV10) GetRedis() map[string]redisNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.Redis return s.Notify.Redis
} }
// GetRedisNotify get current Redis logger. // GetRedisNotify get current Redis logger.
func (s serverConfigV9) GetRedisNotifyByID(accountID string) redisNotify { func (s serverConfigV10) GetRedisNotifyByID(accountID string) redisNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.Redis[accountID] return s.Notify.Redis[accountID]
} }
func (s *serverConfigV9) SetPostgreSQLNotifyByID(accountID string, pgn postgreSQLNotify) { func (s *serverConfigV10) SetPostgreSQLNotifyByID(accountID string, pgn postgreSQLNotify) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Notify.PostgreSQL[accountID] = pgn s.Notify.PostgreSQL[accountID] = pgn
} }
func (s serverConfigV9) GetPostgreSQL() map[string]postgreSQLNotify { func (s serverConfigV10) GetPostgreSQL() map[string]postgreSQLNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.PostgreSQL return s.Notify.PostgreSQL
} }
func (s serverConfigV9) GetPostgreSQLNotifyByID(accountID string) postgreSQLNotify { func (s serverConfigV10) GetPostgreSQLNotifyByID(accountID string) postgreSQLNotify {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Notify.PostgreSQL[accountID] return s.Notify.PostgreSQL[accountID]
} }
// SetFileLogger set new file logger. // SetFileLogger set new file logger.
func (s *serverConfigV9) SetFileLogger(flogger fileLogger) { func (s *serverConfigV10) SetFileLogger(flogger fileLogger) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Logger.File = flogger s.Logger.File = flogger
} }
// GetFileLogger get current file logger. // GetFileLogger get current file logger.
func (s serverConfigV9) GetFileLogger() fileLogger { func (s serverConfigV10) GetFileLogger() fileLogger {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Logger.File return s.Logger.File
} }
// SetConsoleLogger set new console logger. // SetConsoleLogger set new console logger.
func (s *serverConfigV9) SetConsoleLogger(clogger consoleLogger) { func (s *serverConfigV10) SetConsoleLogger(clogger consoleLogger) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Logger.Console = clogger s.Logger.Console = clogger
} }
// GetConsoleLogger get current console logger. // GetConsoleLogger get current console logger.
func (s serverConfigV9) GetConsoleLogger() consoleLogger { func (s serverConfigV10) GetConsoleLogger() consoleLogger {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Logger.Console return s.Logger.Console
} }
// SetSyslogLogger set new syslog logger.
func (s *serverConfigV9) SetSyslogLogger(slogger syslogLogger) {
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
s.Logger.Syslog = slogger
}
// GetSyslogLogger get current syslog logger.
func (s *serverConfigV9) GetSyslogLogger() syslogLogger {
s.rwMutex.RLock()
defer s.rwMutex.RUnlock()
return s.Logger.Syslog
}
// SetRegion set new region. // SetRegion set new region.
func (s *serverConfigV9) SetRegion(region string) { func (s *serverConfigV10) SetRegion(region string) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Region = region s.Region = region
} }
// GetRegion get current region. // GetRegion get current region.
func (s serverConfigV9) GetRegion() string { func (s serverConfigV10) GetRegion() string {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Region return s.Region
} }
// SetCredentials set new credentials. // SetCredentials set new credentials.
func (s *serverConfigV9) SetCredential(creds credential) { func (s *serverConfigV10) SetCredential(creds credential) {
s.rwMutex.Lock() s.rwMutex.Lock()
defer s.rwMutex.Unlock() defer s.rwMutex.Unlock()
s.Credential = creds s.Credential = creds
} }
// GetCredentials get current credentials. // GetCredentials get current credentials.
func (s serverConfigV9) GetCredential() credential { func (s serverConfigV10) GetCredential() credential {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()
return s.Credential return s.Credential
} }
// Save config. // Save config.
func (s serverConfigV9) Save() error { func (s serverConfigV10) Save() error {
s.rwMutex.RLock() s.rwMutex.RLock()
defer s.rwMutex.RUnlock() defer s.rwMutex.RUnlock()

View File

@ -78,15 +78,6 @@ func TestServerConfig(t *testing.T) {
t.Errorf("Expecting file logger config %#v found %#v", fileLogger{Enable: true}, consoleCfg) t.Errorf("Expecting file logger config %#v found %#v", fileLogger{Enable: true}, consoleCfg)
} }
// Set new syslog logger.
serverConfig.SetSyslogLogger(syslogLogger{
Enable: true,
})
sysLogCfg := serverConfig.GetSyslogLogger()
if !reflect.DeepEqual(sysLogCfg, syslogLogger{Enable: true}) {
t.Errorf("Expecting syslog logger config %#v found %#v", syslogLogger{Enable: true}, sysLogCfg)
}
// Match version. // Match version.
if serverConfig.GetVersion() != globalMinioConfigVersion { if serverConfig.GetVersion() != globalMinioConfigVersion {
t.Errorf("Expecting version %s found %s", serverConfig.GetVersion(), globalMinioConfigVersion) t.Errorf("Expecting version %s found %s", serverConfig.GetVersion(), globalMinioConfigVersion)

View File

@ -32,7 +32,7 @@ const (
// minio configuration related constants. // minio configuration related constants.
const ( const (
globalMinioConfigVersion = "9" globalMinioConfigVersion = "10"
globalMinioConfigDir = ".minio" globalMinioConfigDir = ".minio"
globalMinioCertsDir = "certs" globalMinioCertsDir = "certs"
globalMinioCertsCADir = "CAs" globalMinioCertsCADir = "CAs"

View File

@ -1,90 +0,0 @@
// +build !windows
/*
* Minio Cloud Storage, (C) 2015, 2016 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import (
"fmt"
"io/ioutil"
"log/syslog"
"github.com/Sirupsen/logrus"
)
type syslogLogger struct {
Enable bool `json:"enable"`
Addr string `json:"address"`
Level string `json:"level"`
}
// syslogHook to send logs via syslog.
type syslogHook struct {
writer *syslog.Writer
syslogNetwork string
syslogRaddr string
}
// enableSyslogLogger - enable logger at raddr.
func enableSyslogLogger(raddr string) {
syslogHook, err := newSyslog("udp", raddr, syslog.LOG_ERR, "MINIO")
fatalIf(err, "Unable to initialize syslog logger.")
sysLogger := logrus.New()
sysLogger.Hooks.Add(syslogHook) // Add syslog hook.
sysLogger.Formatter = &logrus.JSONFormatter{} // JSON formatted log.
sysLogger.Level = logrus.ErrorLevel // Minimum log level.
sysLogger.Out = ioutil.Discard
log.mu.Lock()
log.loggers = append(log.loggers, sysLogger)
log.mu.Unlock()
}
// newSyslog - Creates a hook to be added to an instance of logger.
func newSyslog(network, raddr string, priority syslog.Priority, tag string) (*syslogHook, error) {
w, err := syslog.Dial(network, raddr, priority, tag)
return &syslogHook{w, network, raddr}, err
}
// Fire - fire the log event
func (hook *syslogHook) Fire(entry *logrus.Entry) error {
line, err := entry.String()
if err != nil {
return fmt.Errorf("Unable to read entry, %v", err)
}
switch entry.Level {
case logrus.PanicLevel:
return hook.writer.Crit(line)
case logrus.FatalLevel:
return hook.writer.Crit(line)
case logrus.ErrorLevel:
return hook.writer.Err(line)
default:
return nil
}
}
// Levels -
func (hook *syslogHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
}
}

View File

@ -1,30 +0,0 @@
// +build windows
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
type syslogLogger struct {
Enable bool `json:"enable"`
Addr string `json:"address"`
Level string `json:"level"`
}
// enableSyslogLogger - unsupported on windows.
func enableSyslogLogger(raddr string) {
fatalIf(errSyslogNotSupported, "Unable to enable syslog.")
}

View File

@ -38,11 +38,9 @@ var log = struct {
// //
// - console [default] // - console [default]
// - file // - file
// - syslog
type logger struct { type logger struct {
Console consoleLogger `json:"console"` Console consoleLogger `json:"console"`
File fileLogger `json:"file"` File fileLogger `json:"file"`
Syslog syslogLogger `json:"syslog"`
// Add new loggers here. // Add new loggers here.
} }

View File

@ -18,9 +18,6 @@ package cmd
import "errors" import "errors"
// errSyslogNotSupported - this message is only meaningful on windows
var errSyslogNotSupported = errors.New("Syslog logger not supported on windows")
// errInvalidArgument means that input argument is invalid. // errInvalidArgument means that input argument is invalid.
var errInvalidArgument = errors.New("Invalid arguments specified") var errInvalidArgument = errors.New("Invalid arguments specified")