<commit_before>package logging

import (
	"fmt"
	"io"
	"os"
	"path"
	"strings"
	"sync"
	"time"
)

const (
	DEBUG = iota
	INFO
	WARNING
	ERROR
	DISABLE
	LAYOUT = "2006-01-02 15:04:05"
)

type Logger struct {
	mutex   sync.Mutex
	prefix  string
	out     io.WriteCloser
	level   int
	layout  string
	handler func(log string)
	data    map[string]string
}

func New(out io.WriteCloser, prefix string, level int, layout string) *Logger {
	return &Logger{out: out, prefix: prefix, level: level, layout: layout}
}

var std = New(os.Stdout, "", DEBUG, LAYOUT)

func (l *Logger) SetPrefix(prefix string) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.prefix = prefix
}

func (l *Logger) SetLevel(level int) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.level = level
}

func (l *Logger) SetWriter(out io.WriteCloser) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.out = out
}

func (l *Logger) SetLayout(layout string) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.layout = layout
}

func (l *Logger) Level() int {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	return l.level
}

func (l *Logger) Prefix() string {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	return l.prefix
}

func (l *Logger) timestamp() string {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	return time.Now().Format(l.layout)
}

func (l *Logger) head(level string) string {
	a := []string{"[", l.timestamp(), "] ", level, " ", l.Prefix(), " "}
	return strings.Join(a, "")
}

func (l *Logger) log(level string, format string, v ...interface{}) {
	log := l.head(level) + fmt.Sprintf(strings.TrimRight(format, "\n")+"\n", v...)
	if l.handler != nil {
		l.handler(log)
	}
	l.mutex.Lock()
	defer l.mutex.Unlock()
	fmt.Fprint(l.out, log)
}

func (l *Logger) Debug(format string, v ...interface{}) {
	if l.Level() <= DEBUG {
		l.log("DEBUG", format, v...)
	}
}

func (l *Logger) Info(format string, v ...interface{}) {
	if l.Level() <= INFO {
		l.log("INFO", format, v...)
	}
}

func (l *Logger) Warning(format string, v ...interface{}) {
	if l.Level() <= WARNING {
		l.log("WARNING", format, v...)
	}
}

func (l *Logger) Error(format string, v ...interface{}) {
	if l.Level() <= ERROR {<commit_msg>exchange the position of level and prefix<commit_after>package logging

import (
	"fmt"
	"io"
	"os"
	"path"
	"strings"
	"sync"
	"time"
)

const (
	DEBUG = iota
	INFO
	WARNING
	ERROR
	DISABLE
	LAYOUT = "2006-01-02 15:04:05"
)

type Logger struct {
	mutex   sync.Mutex
	prefix  string
	out     io.WriteCloser
	level   int
	layout  string
	handler func(log string)
	data    map[string]string
}

func New(out io.WriteCloser, prefix string, level int, layout string) *Logger {
	return &Logger{out: out, prefix: prefix, level: level, layout: layout}
}

var std = New(os.Stdout, "", DEBUG, LAYOUT)

func (l *Logger) SetPrefix(prefix string) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.prefix = prefix
}

func (l *Logger) SetLevel(level int) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.level = level
}

func (l *Logger) SetWriter(out io.WriteCloser) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.out = out
}

func (l *Logger) SetLayout(layout string) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.layout = layout
}

func (l *Logger) Level() int {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	return l.level
}

func (l *Logger) Prefix() string {
	return l.prefix
}

func (l *Logger) timestamp() string {
	return time.Now().Format(l.layout)
}

func (l *Logger) head(level string) string {
	a := []string{"[", l.timestamp(), "]"}
	p := l.Prefix()
	if p != "" {
		a = append(a, " ", p)
	}
	a = append(a, " ", level)
	return strings.Join(a, "")
}

func (l *Logger) log(level string, format string, v ...interface{}) {
	log := l.head(level) + " " + fmt.Sprintf(strings.TrimRight(format, "\n")+"\n", v...)
	if l.handler != nil {
		l.handler(log)
	}
	l.mutex.Lock()
	defer l.mutex.Unlock()
	fmt.Fprint(l.out, log)
}

func (l *Logger) Debug(format string, v ...interface{}) {
	if l.Level() <= DEBUG {
		l.log("DEBUG", format, v...)
	}
}

func (l *Logger) Info(format string, v ...interface{}) {
	if l.Level() <= INFO {
		l.log("INFO", format, v...)
	}
}

func (l *Logger) Warning(format string, v ...interface{}) {
	if l.Level() <= WARNING {
		l.log("WARNING", format, v...)
	}
}

func (l *Logger) Error(format string, v ...interface{}) {
	if l.Level() <= ERROR {
{'fraction_non_alphanumeric': 0.1854970760233918, 'fraction_numerical': 0.006549707602339181, 'mean_word_length': 3.4821802935010484, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2909728', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1658, 'n_words': 442}