Enable all config loggers

master
Harshavardhana 9 years ago
parent bf644aaba9
commit 09e51002ed
  1. 61
      config-logger-main.go
  2. 0
      logger-syslog-hook_linux.go
  3. 25
      logger-syslog-hook_windows.go
  4. 54
      server-config.go
  5. 37
      server-main.go
  6. 3
      typed-errors.go

@ -17,7 +17,7 @@
package main package main
import ( import (
"fmt" "runtime"
"github.com/minio/cli" "github.com/minio/cli"
"github.com/minio/minio-xl/pkg/probe" "github.com/minio/minio-xl/pkg/probe"
@ -32,42 +32,31 @@ var configLoggerCmd = cli.Command{
minio config {{.Name}} - {{.Usage}} minio config {{.Name}} - {{.Usage}}
USAGE: USAGE:
minio config {{.Name}} minio config {{.Name}} OPERATION [ARGS...]
`, OPERATION = add | list | remove
}
// Inherit at one place EXAMPLES:
type config struct { 1. Configure new mongo logger.
*configV2 $ minio config {{.Name}} add mongo localhost:28710 mydb mylogger
}
func (c *config) IsFileLoggingEnabled() bool { 2. Configure new syslog logger. NOTE: syslog logger is not supported on windows.
if c.FileLogger.Filename != "" { $ minio config {{.Name}} add syslog localhost:554 udp
return true
}
return false
}
func (c *config) IsSysloggingEnabled() bool { 3. Configure new file logger. "/var/log" should be writable by user.
if c.SyslogLogger.Network != "" && c.SyslogLogger.Addr != "" { $ minio config {{.Name}} add file /var/log/minio.log
return true
}
return false
}
func (c *config) IsMongoLoggingEnabled() bool { 4. List currently configured logger.
if c.MongoLogger.Addr != "" && c.MongoLogger.DB != "" && c.MongoLogger.Collection != "" { $ minio config {{.Name}} list
return true
} 5. Remove/Reset a configured logger.
return false $ minio config {{.Name}} remove mongo
`,
} }
func (c *config) String() string { // Inherit at one place
str := fmt.Sprintf("Mongo -> Addr: %s, DB: %s, Collection: %s\n", c.MongoLogger.Addr, c.MongoLogger.DB, c.MongoLogger.Collection) type config struct {
str = str + fmt.Sprintf("Syslog -> Addr: %s, Network: %s\n", c.SyslogLogger.Addr, c.SyslogLogger.Network) *configV2
str = str + fmt.Sprintf("File -> Filename: %s", c.FileLogger.Filename)
return str
} }
func mainConfigLogger(ctx *cli.Context) { func mainConfigLogger(ctx *cli.Context) {
@ -83,6 +72,9 @@ func mainConfigLogger(ctx *cli.Context) {
enableLog2Mongo(&config{conf}, args.Tail()) enableLog2Mongo(&config{conf}, args.Tail())
} }
if args.Get(0) == "syslog" { if args.Get(0) == "syslog" {
if runtime.GOOS == "windows" {
fatalIf(probe.NewError(errInvalidArgument), "Syslog is not supported on windows.", nil)
}
enableLog2Syslog(&config{conf}, args.Tail()) enableLog2Syslog(&config{conf}, args.Tail())
} }
if args.Get(0) == "file" { if args.Get(0) == "file" {
@ -99,6 +91,9 @@ func mainConfigLogger(ctx *cli.Context) {
fatalIf(err.Trace(), "Unable to save config.", nil) fatalIf(err.Trace(), "Unable to save config.", nil)
} }
if args.Get(0) == "syslog" { if args.Get(0) == "syslog" {
if runtime.GOOS == "windows" {
fatalIf(probe.NewError(errInvalidArgument), "Syslog is not supported on windows.", nil)
}
conf.SyslogLogger.Network = "" conf.SyslogLogger.Network = ""
conf.SyslogLogger.Addr = "" conf.SyslogLogger.Addr = ""
err := saveConfig(conf) err := saveConfig(conf)
@ -111,7 +106,11 @@ func mainConfigLogger(ctx *cli.Context) {
} }
} }
if ctx.Args().Get(0) == "list" { if ctx.Args().Get(0) == "list" {
Println(&config{conf}) if globalJSONFlag {
Println(conf.JSON())
return
}
Println(conf)
} }
} }

@ -0,0 +1,25 @@
// +build windows
/*
* 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 "github.com/minio/minio-xl/pkg/probe"
func log2Syslog(network, raddr string) *probe.Error {
return probe.NewError(errSysLogNotSupported)
}

@ -17,7 +17,9 @@
package main package main
import ( import (
"encoding/json"
"errors" "errors"
"fmt"
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
@ -54,6 +56,58 @@ type configV2 struct {
} `json:"fileLogger"` } `json:"fileLogger"`
} }
func (c *configV2) IsFileLoggingEnabled() bool {
if c.FileLogger.Filename != "" {
return true
}
return false
}
func (c *configV2) IsSysloggingEnabled() bool {
if c.SyslogLogger.Network != "" && c.SyslogLogger.Addr != "" {
return true
}
return false
}
func (c *configV2) IsMongoLoggingEnabled() bool {
if c.MongoLogger.Addr != "" && c.MongoLogger.DB != "" && c.MongoLogger.Collection != "" {
return true
}
return false
}
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)
return str
}
func (c *configV2) JSON() string {
type logger struct {
MongoLogger struct {
Addr string `json:"addr"`
DB string `json:"db"`
Collection string `json:"collection"`
} `json:"mongoLogger"`
SyslogLogger struct {
Network string `json:"network"`
Addr string `json:"addr"`
} `json:"syslogLogger"`
FileLogger struct {
Filename string `json:"filename"`
} `json:"fileLogger"`
}
loggerBytes, err := json.Marshal(logger{
MongoLogger: c.MongoLogger,
SyslogLogger: c.SyslogLogger,
FileLogger: c.FileLogger,
})
fatalIf(probe.NewError(err), "Unable to marshal logger struct into JSON.", nil)
return string(loggerBytes)
}
// getConfigPath get users config path // getConfigPath get users config path
func getConfigPath() (string, *probe.Error) { func getConfigPath() (string, *probe.Error) {
if customConfigPath != "" { if customConfigPath != "" {

@ -168,8 +168,30 @@ func parsePercentToInt(s string, bitSize int) (int64, *probe.Error) {
} }
return p, nil return p, nil
} }
func setLogger(conf *configV2) *probe.Error {
if conf.IsMongoLoggingEnabled() {
err := log2Mongo(conf.MongoLogger.Addr, conf.MongoLogger.DB, conf.MongoLogger.Collection)
if err != nil {
return err.Trace()
}
}
if conf.IsSysloggingEnabled() {
err := log2Syslog(conf.SyslogLogger.Network, conf.SyslogLogger.Addr)
if err != nil {
return err.Trace()
}
}
if conf.IsFileLoggingEnabled() {
err := log2File(conf.FileLogger.Filename)
if err != nil {
return err.Trace()
}
}
return nil
}
func getAuth() (*configV2, *probe.Error) { // Generates config if it doesn't exist, otherwise returns back the saved ones.
func getConfig() (*configV2, *probe.Error) {
if err := createConfigPath(); err != nil { if err := createConfigPath(); err != nil {
return nil, err.Trace() return nil, err.Trace()
} }
@ -208,12 +230,15 @@ func (a accessKeys) JSON() string {
return string(b) return string(b)
} }
// fetchAuth first time authorization // initServer initialize server
func fetchAuth() *probe.Error { func initServer() *probe.Error {
conf, err := getAuth() conf, err := getConfig()
if err != nil { if err != nil {
return err.Trace() return err.Trace()
} }
if err := setLogger(conf); err != nil {
return err.Trace()
}
if conf != nil { if conf != nil {
if globalJSONFlag { if globalJSONFlag {
Println(accessKeys{conf}.JSON()) Println(accessKeys{conf}.JSON())
@ -257,8 +282,8 @@ func checkServerSyntax(c *cli.Context) {
func serverMain(c *cli.Context) { func serverMain(c *cli.Context) {
checkServerSyntax(c) checkServerSyntax(c)
perr := fetchAuth() perr := initServer()
fatalIf(perr.Trace(), "Failed to generate keys for minio.", nil) fatalIf(perr.Trace(), "Failed to read config for minio.", nil)
certFile := c.GlobalString("cert") certFile := c.GlobalString("cert")
keyFile := c.GlobalString("key") keyFile := c.GlobalString("key")

@ -18,6 +18,9 @@ package main
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")

Loading…
Cancel
Save