func init() { debugLogger = golog.GetLogger("debug") debugLogger.Enable(appenders.File(golog.Conf{ "path": "./debug.log", })) debugLogger.Disable(golog.StdoutAppender()) debugLogger.Level = golog.DEBUG infoLogger = golog.GetLogger("info") infoLogger.Enable(appenders.File(golog.Conf{ "path": "./info.log", })) infoLogger.Disable(golog.StdoutAppender()) infoLogger.Level = golog.INFO warnLogger = golog.GetLogger("warn") warnLogger.Enable(appenders.File(golog.Conf{ "path": "./warn.log", })) warnLogger.Disable(golog.StdoutAppender()) warnLogger.Level = golog.WARN errorLogger = golog.GetLogger("error") errorLogger.Enable(appenders.File(golog.Conf{ "path": "./error.log", })) errorLogger.Disable(golog.StdoutAppender()) errorLogger.Level = golog.ERROR }
func init() { logPath := os.Getenv("LOG_PATH") if logPath == "" { logPath = "/tmp" } debugLogger = golog.GetLogger("debug") debugLogger.Enable(appenders.File(golog.Conf{ "path": logPath + "/debug.log", })) debugLogger.Disable(golog.StdoutAppender()) debugLogger.Level = golog.DEBUG infoLogger = golog.GetLogger("info") infoLogger.Enable(appenders.File(golog.Conf{ "path": logPath + "/info.log", })) infoLogger.Disable(golog.StdoutAppender()) infoLogger.Level = golog.INFO warnLogger = golog.GetLogger("warn") warnLogger.Enable(appenders.File(golog.Conf{ "path": logPath + "/warn.log", })) warnLogger.Disable(golog.StdoutAppender()) warnLogger.Level = golog.WARN errorLogger = golog.GetLogger("error") errorLogger.Enable(appenders.File(golog.Conf{ "path": logPath + "/error.log", })) errorLogger.Disable(golog.StdoutAppender()) errorLogger.Level = golog.ERROR }
func file() { logger := golog.Default // make instance of file appender and enable it logger.Enable(appenders.File(golog.Conf{ "path": "/path/to/log.txt", })) logger.Debug("some message") }
func advanced() { logger := golog.Default logger.Debug("some message") // you can provide additional data to log additionalData := &TestStruct{} logger.Debug("some message", additionalData) // you can require logger instance application := golog.GetLogger("application") // set log level application.Level = golog.WARN application.Info("log from application logger") appender := appenders.File(golog.Conf{ "path": "/path/to/log.txt", }) // you can enable appender application.Enable(appender) // you can disable appender by passing reference application.Disable(appender) // you can disable appender by passing appender id // id is returned with appender.Id() method application.Disable("github.com/ivpusic/golog/appender/file") // you can disable some logger completely // you have to provide logger name in order to disable it golog.Disable("github.com/someuser/somelib") // all loggers are enabled by default // if you have case that at some point you disable it, // and later you want to enable it again, you can use this method golog.Enable("github.com/someuser/somelib") }