Beispiel #1
0
// NewRotatableLogger creates a rotatable file logger with buffering and a priority filter
// Note: if path is empty, logs will be written to stdout
func NewRotatableLogger(path, format string, fields []string, logLevel int, verbose bool) (*Logger, error) {
	var sinks []log.Sink
	if len(path) > 0 {
		rfw, err := NewRotatableFileWriter(
			path,
			os.O_CREATE|os.O_APPEND|os.O_WRONLY,
			os.FileMode(0644),
			5*time.Second)
		if err != nil {
			return nil, err
		}

		sinks = []log.Sink{
			NewCloseablePriorityFilter(
				log.Priority(logLevel),
				NewCloseableBufferedWriterSink(1<<8, rfw, format, fields),
			),
		}
	} else {
		sinks = []log.Sink{
			log.PriorityFilter(
				log.Priority(logLevel),
				log.WriterSink(os.Stdout, format, fields),
			),
		}
	}

	return NewLogger("", verbose, sinks...), nil
}
Beispiel #2
0
func Priority(p int) string {
	return log.Priority(p).String()
}