logger: Improve logger input argument handling and colorize outputs

master
Harshavardhana 9 years ago
parent 02d843ef5d
commit 15909e5463
  1. 30
      config-logger-main.go
  2. 8
      flags.go
  3. 16
      logger-file-hook.go
  4. 2
      main.go
  5. 17
      server-config.go

@ -116,40 +116,52 @@ func mainConfigLogger(ctx *cli.Context) {
func enableLog2Mongo(conf *config, args cli.Args) {
if conf.IsFileLoggingEnabled() {
fatalIf(probe.NewError(errInvalidArgument), "File logging already enabled. Please remove before enabling mongo.", nil)
Infoln("File logging already enabled. Removing automatically by enabling mongo.")
conf.FileLogger.Filename = ""
}
if conf.IsSysloggingEnabled() {
fatalIf(probe.NewError(errInvalidArgument), "Syslog logging already enabled. Please remove before enabling mongo.", nil)
Infoln("Syslog logging already enabled. Removing automatically by enabling mongo.")
conf.SyslogLogger.Addr = ""
conf.SyslogLogger.Network = ""
}
conf.MongoLogger.Addr = args.Get(0)
conf.MongoLogger.DB = args.Get(1)
conf.MongoLogger.Collection = args.Get(2)
err := saveConfig(conf.configV2)
fatalIf(err.Trace(), "Unable to save config.", nil)
fatalIf(err.Trace(), "Unable to save mongo logging config.", nil)
}
func enableLog2Syslog(conf *config, args cli.Args) {
if conf.IsFileLoggingEnabled() {
fatalIf(probe.NewError(errInvalidArgument), "File logging already enabled. Please remove before enabling syslog.", nil)
Infoln("File logging already enabled. Removing automatically by enabling syslog.")
conf.FileLogger.Filename = ""
}
if conf.IsMongoLoggingEnabled() {
fatalIf(probe.NewError(errInvalidArgument), "Mongo logging already enabled. Please remove before enabling syslog.", nil)
Infoln("Mongo logging already enabled. Removing automatically by enabling syslog.")
conf.MongoLogger.Addr = ""
conf.MongoLogger.DB = ""
conf.MongoLogger.Collection = ""
}
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 syslog config.", nil)
}
func enableLog2File(conf *config, args cli.Args) {
if conf.IsSysloggingEnabled() {
fatalIf(probe.NewError(errInvalidArgument), "Syslog logging already enabled. Please remove before enabling file.", nil)
Infoln("Syslog logging already enabled. Removing automatically by enabling file logging.")
conf.SyslogLogger.Addr = ""
conf.SyslogLogger.Network = ""
}
if conf.IsMongoLoggingEnabled() {
fatalIf(probe.NewError(errInvalidArgument), "Mongo logging already enabled. Please remove before enabling file.", nil)
Infoln("Mongo logging already enabled. Removing automatically by enabling file logging.")
conf.MongoLogger.Addr = ""
conf.MongoLogger.DB = ""
conf.MongoLogger.Collection = ""
}
conf.FileLogger.Filename = args.Get(0)
err := saveConfig(conf.configV2)
fatalIf(err.Trace(), "Unable to save config.", nil)
fatalIf(err.Trace(), "Unable to save file logging config.", nil)
}

@ -28,19 +28,13 @@ var (
Usage: "ADDRESS:PORT for cloud storage access.",
}
loggerFlag = cli.StringFlag{
Name: "logger",
Value: "none",
Usage: "Choose type of logging. Available options are [‘file’, ‘mongo’, ‘syslog’]",
}
accessLogFlag = cli.BoolFlag{
Name: "enable-accesslog",
Hide: true,
Usage: "Enable access logs for all incoming HTTP request.",
}
ratelimitFlag = cli.IntFlag{
rateLimitFlag = cli.IntFlag{
Name: "ratelimit",
Hide: true,
Value: 0,

@ -1,3 +1,19 @@
/*
* Minio Cloud Storage, (C) 2015 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 main
import (

@ -92,7 +92,7 @@ func registerApp() *cli.App {
// register all flags
registerFlag(addressFlag)
registerFlag(accessLogFlag)
registerFlag(ratelimitFlag)
registerFlag(rateLimitFlag)
registerFlag(anonymousFlag)
registerFlag(certFlag)
registerFlag(keyFlag)

@ -24,6 +24,7 @@ import (
"os/user"
"path/filepath"
"github.com/fatih/color"
"github.com/minio/minio-xl/pkg/probe"
"github.com/minio/minio-xl/pkg/quick"
)
@ -78,9 +79,19 @@ func (c *configV2) IsMongoLoggingEnabled() bool {
}
func (c *configV2) 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)
white := color.New(color.FgWhite, color.Bold).SprintfFunc()
var str string
if c.IsMongoLoggingEnabled() {
str = fmt.Sprintf("Mongo -> %s", white("Addr: %s, DB: %s, Collection: %s",
c.MongoLogger.Addr, c.MongoLogger.DB, c.MongoLogger.Collection))
}
if c.IsSysloggingEnabled() {
str = fmt.Sprintf("Syslog -> %s", white("Addr: %s, Network: %s",
c.SyslogLogger.Addr, c.SyslogLogger.Network))
}
if c.IsFileLoggingEnabled() {
str = fmt.Sprintf("File -> %s", white("Filename: %s", c.FileLogger.Filename))
}
return str
}

Loading…
Cancel
Save