|
|
@ -16,7 +16,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
package main |
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import "github.com/minio/cli" |
|
|
|
import ( |
|
|
|
|
|
|
|
"fmt" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/minio/cli" |
|
|
|
|
|
|
|
"github.com/minio/minio-xl/pkg/probe" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Configure logger
|
|
|
|
// Configure logger
|
|
|
|
var configLoggerCmd = cli.Command{ |
|
|
|
var configLoggerCmd = cli.Command{ |
|
|
@ -32,47 +37,120 @@ USAGE: |
|
|
|
`, |
|
|
|
`, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Inherit at one place
|
|
|
|
|
|
|
|
type config struct { |
|
|
|
|
|
|
|
*configV2 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *config) IsFileLoggingEnabled() bool { |
|
|
|
|
|
|
|
if c.FileLogger.Filename != "" { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *config) IsSysloggingEnabled() bool { |
|
|
|
|
|
|
|
if c.SyslogLogger.Network != "" && c.SyslogLogger.Addr != "" { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *config) IsMongoLoggingEnabled() bool { |
|
|
|
|
|
|
|
if c.MongoLogger.Addr != "" && c.MongoLogger.DB != "" && c.MongoLogger.Collection != "" { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *config) String() string { |
|
|
|
|
|
|
|
str := fmt.Sprintf("Mongo -> Addr: %s, DB: %s, Collection: %s\n", c.MongoLogger.Addr, c.MongoLogger.DB, c.MongoLogger.Collection) |
|
|
|
|
|
|
|
str = str + fmt.Sprintf("Syslog -> Addr: %s, Network: %s\n", c.SyslogLogger.Addr, c.SyslogLogger.Network) |
|
|
|
|
|
|
|
str = str + fmt.Sprintf("File -> Filename: %s", c.FileLogger.Filename) |
|
|
|
|
|
|
|
return str |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func mainConfigLogger(ctx *cli.Context) { |
|
|
|
func mainConfigLogger(ctx *cli.Context) { |
|
|
|
if !ctx.Args().Present() || ctx.Args().First() == "help" { |
|
|
|
if !ctx.Args().Present() || ctx.Args().First() == "help" { |
|
|
|
cli.ShowCommandHelpAndExit(ctx, "logger", 1) // last argument is exit code
|
|
|
|
cli.ShowCommandHelpAndExit(ctx, "logger", 1) // last argument is exit code
|
|
|
|
} |
|
|
|
} |
|
|
|
if ctx.Args().Get(0) == "mongo" { |
|
|
|
conf, err := loadConfigV2() |
|
|
|
enableLog2Mongo(ctx.Args().Tail()) |
|
|
|
fatalIf(err.Trace(), "Unable to load config", nil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.Args().Get(0) == "add" { |
|
|
|
|
|
|
|
args := ctx.Args().Tail() |
|
|
|
|
|
|
|
if args.Get(0) == "mongo" { |
|
|
|
|
|
|
|
enableLog2Mongo(&config{conf}, args.Tail()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if args.Get(0) == "syslog" { |
|
|
|
|
|
|
|
enableLog2Syslog(&config{conf}, args.Tail()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if args.Get(0) == "file" { |
|
|
|
|
|
|
|
enableLog2File(&config{conf}, args.Tail()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if ctx.Args().Get(0) == "syslog" { |
|
|
|
if ctx.Args().Get(0) == "remove" { |
|
|
|
enableLog2Syslog(ctx.Args().Tail()) |
|
|
|
args := ctx.Args().Tail() |
|
|
|
|
|
|
|
if args.Get(0) == "mongo" { |
|
|
|
|
|
|
|
conf.MongoLogger.Addr = "" |
|
|
|
|
|
|
|
conf.MongoLogger.DB = "" |
|
|
|
|
|
|
|
conf.MongoLogger.Collection = "" |
|
|
|
|
|
|
|
err := saveConfig(conf) |
|
|
|
|
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if args.Get(0) == "syslog" { |
|
|
|
|
|
|
|
conf.SyslogLogger.Network = "" |
|
|
|
|
|
|
|
conf.SyslogLogger.Addr = "" |
|
|
|
|
|
|
|
err := saveConfig(conf) |
|
|
|
|
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if args.Get(0) == "file" { |
|
|
|
|
|
|
|
conf.FileLogger.Filename = "" |
|
|
|
|
|
|
|
err := saveConfig(conf) |
|
|
|
|
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if ctx.Args().Get(0) == "file" { |
|
|
|
if ctx.Args().Get(0) == "list" { |
|
|
|
enableLog2File(ctx.Args().Tail()) |
|
|
|
Println(&config{conf}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func enableLog2Mongo(args cli.Args) { |
|
|
|
func enableLog2Mongo(conf *config, args cli.Args) { |
|
|
|
config, err := loadConfigV2() |
|
|
|
if conf.IsFileLoggingEnabled() { |
|
|
|
fatalIf(err.Trace(), "Unable to load config", nil) |
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "File logging already enabled. Please remove before enabling mongo.", nil) |
|
|
|
|
|
|
|
} |
|
|
|
config.MongoLogger.Addr = args.Get(0) |
|
|
|
if conf.IsSysloggingEnabled() { |
|
|
|
config.MongoLogger.DB = args.Get(1) |
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Syslog logging already enabled. Please remove before enabling mongo.", nil) |
|
|
|
config.MongoLogger.Collection = args.Get(2) |
|
|
|
} |
|
|
|
|
|
|
|
conf.MongoLogger.Addr = args.Get(0) |
|
|
|
|
|
|
|
conf.MongoLogger.DB = args.Get(1) |
|
|
|
|
|
|
|
conf.MongoLogger.Collection = args.Get(2) |
|
|
|
|
|
|
|
|
|
|
|
err = saveConfig(config) |
|
|
|
err := saveConfig(conf.configV2) |
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func enableLog2Syslog(args cli.Args) { |
|
|
|
func enableLog2Syslog(conf *config, args cli.Args) { |
|
|
|
config, err := loadConfigV2() |
|
|
|
if conf.IsFileLoggingEnabled() { |
|
|
|
fatalIf(err.Trace(), "Unable to load config.", nil) |
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "File logging already enabled. Please remove before enabling syslog.", nil) |
|
|
|
|
|
|
|
} |
|
|
|
config.SyslogLogger.Addr = args.Get(0) |
|
|
|
if conf.IsMongoLoggingEnabled() { |
|
|
|
config.SyslogLogger.Network = args.Get(1) |
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Mongo logging already enabled. Please remove before enabling syslog.", nil) |
|
|
|
err = saveConfig(config) |
|
|
|
} |
|
|
|
|
|
|
|
conf.SyslogLogger.Addr = args.Get(0) |
|
|
|
|
|
|
|
conf.SyslogLogger.Network = args.Get(1) |
|
|
|
|
|
|
|
err := saveConfig(conf.configV2) |
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func enableLog2File(args cli.Args) { |
|
|
|
func enableLog2File(conf *config, args cli.Args) { |
|
|
|
config, err := loadConfigV2() |
|
|
|
if conf.IsSysloggingEnabled() { |
|
|
|
fatalIf(err.Trace(), "Unable to load config.", nil) |
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Syslog logging already enabled. Please remove before enabling file.", nil) |
|
|
|
config.FileLogger.Filename = args.Get(0) |
|
|
|
} |
|
|
|
err = saveConfig(config) |
|
|
|
if conf.IsMongoLoggingEnabled() { |
|
|
|
|
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Mongo logging already enabled. Please remove before enabling file.", nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
conf.FileLogger.Filename = args.Get(0) |
|
|
|
|
|
|
|
err := saveConfig(conf.configV2) |
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
fatalIf(err.Trace(), "Unable to save config.", nil) |
|
|
|
} |
|
|
|
} |
|
|
|