Ejemplo n.º 1
0
// SetLogger sets the global logger to write to the given path.
func SetLogger(logPath string) {
	logfile, err := util.GetAppendingFile(logPath)
	if err != nil {
		panic(fmt.Sprintf("Cannot create log file %v: %v", logPath, err))
	}

	Logger = slogger.Logger{
		Prefix:    "",
		Appenders: []slogger.Appender{&slogger.FileAppender{logfile}},
	}
}
Ejemplo n.º 2
0
// NewStreamLogger creates a StreamLogger wrapper for the apiLogger with a given timeoutWatcher.
// Any logged messages on the StreamLogger will reset the TimeoutWatcher.
func NewStreamLogger(timeoutWatcher *TimeoutWatcher, apiLgr *APILogger, logFile string) (*StreamLogger, error) {
	localLogger := slogger.StdOutAppender()

	if logFile != "" {
		appendingFile, err := util.GetAppendingFile(logFile)
		if err != nil {
			return nil, err
		}
		localLogger = &slogger.FileAppender{appendingFile}
	}

	localLoggers := []slogger.Appender{localLogger}
	defaultLoggers := []slogger.Appender{localLogger, apiLgr}

	timeoutLogger := &TimeoutResetLogger{timeoutWatcher, apiLgr}

	return &StreamLogger{
		Local: &slogger.Logger{
			Prefix:    "local",
			Appenders: localLoggers,
		},

		System: &slogger.Logger{
			Prefix:    model.SystemLogPrefix,
			Appenders: defaultLoggers,
		},

		Task: &slogger.Logger{
			Prefix:    model.TaskLogPrefix,
			Appenders: []slogger.Appender{localLogger, timeoutLogger},
		},

		Execution: &slogger.Logger{
			Prefix:    model.AgentLogPrefix,
			Appenders: defaultLoggers,
		},
	}, nil
}