You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

  1. /*
  2. * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package cmd
  17. import (
  18. "fmt"
  19. "strings"
  20. "github.com/Sirupsen/logrus"
  21. )
  22. // consoleLogger - default logger if not other logging is enabled.
  23. type consoleLogger struct {
  24. Enable bool `json:"enable"`
  25. Level string `json:"level"`
  26. }
  27. func (c *consoleLogger) Validate() error {
  28. level := strings.ToLower(c.Level)
  29. if level != "error" && level != "fatal" && level != "" {
  30. return fmt.Errorf("`%s` level value not recognized", c.Level)
  31. }
  32. return nil
  33. }
  34. // enable console logger.
  35. func enableConsoleLogger() {
  36. clogger := serverConfig.Logger.GetConsole()
  37. if !clogger.Enable {
  38. return
  39. }
  40. consoleLogger := logrus.New()
  41. // log.Out and log.Formatter use the default versions.
  42. // Only set specific log level.
  43. lvl, err := logrus.ParseLevel(clogger.Level)
  44. fatalIf(err, "Unknown log level found in the config file.")
  45. consoleLogger.Level = lvl
  46. consoleLogger.Formatter = new(logrus.TextFormatter)
  47. log.mu.Lock()
  48. log.loggers = append(log.loggers, consoleLogger)
  49. log.mu.Unlock()
  50. }