| "github.com/evalphobia/logrus_fluent" |
| "github.com/sirupsen/logrus" |
| var mgrInstance *logManager |
| func (mgr *logManager) SetFluentd(fluentdHost string) { |
| var hook *logrus_fluent.FluentHook |
| if host, portStr, err = net.SplitHostPort(fluentdHost); err != nil { |
| mgr.WithFields(logrus.Fields{ |
| }).Error("Failed to retrieve host/port information") |
| if port, err = strconv.Atoi(portStr); err != nil { |
| mgr.WithFields(logrus.Fields{ |
| }).Error("Failed to convert port to integer") |
| if hook, err = logrus_fluent.NewWithConfig( |
| mgr.WithFields(logrus.Fields{ |
| }).Error("Failed to enable Fluentd hook") |
| hook.SetLevels([]logrus.Level{ |
| mgr.WithFields(logrus.Fields{ |
| }).Info("Added fluentd hook") |
| * It should get initialized only once |
| func Logger() *logManager { |
| _logger.Formatter = new(logrus.JSONFormatter) |
| _logger.Level = logrus.DebugLevel |
| mgrInstance = &logManager{_logger} |