<commit_before>package glogger

import (
	"fmt"
	"log"
	"time"
	"os"
)

const (
	LevelDebug = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal

	defaultTimeFormat   = "2006-01-02 15:04:05"
	defaultformatString = "%s ▶ %.3s %s"
)

var (
	// higher means more serious, log level : DEBUG < INFO < WARN < ERROR < FATAL
	LevelName [5]string = [5]string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"}
	writer    *RotateLogger
)

func Debug(v ...interface{}) {
	output(LevelDebug, fmt.Sprintln(v...))
}

func Debugf(format string, v ...interface{}) {
	output(LevelDebug, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Info(v ...interface{}) {
	output(LevelInfo, fmt.Sprintln(v...))
}

func Infof(format string, v ...interface{}) {
	output(LevelInfo, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Warn(v ...interface{}) {
	output(LevelWarn, fmt.Sprintln(v...))
}

func Warnf(format string, v ...interface{}) {
	output(LevelWarn, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Error(v ...interface{}) {
	output(LevelError, fmt.Sprintln(v...))
}

func Errorf(format string, v ...interface{}) {
	output(LevelError, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Fatal(v ...interface{}) {
	output(LevelFatal, fmt.Sprintln(v...))
	os.Exit(1)
}

func Fatalf(format string, v ...interface{}) {
	output(LevelFatal, fmt.Sprintln(fmt.Sprintf(format, v...)))
	os.Exit(1)
}

func Setup(path string, level int) error {
	var err error
	if writer, err = NewRotateLogger(path, level); err != nil {
		return err
	}
	return nil
}

func SetLevel(level int) {
	writer.SetLevel(level)
}

func Level(level int) int {
	return writer.Level()
}

func output(level int, content string) {
	if level < writer.Level() {
		return
	}

	//the writer may be close
	logContent := fmt.Sprintf(defaultformatString, time.Now().Format(defaultTimeFormat), LevelName[level], content)
	if writer != nil {
		buf := make([]byte, len(logContent))
		copy(buf, logContent)
		writer.Write(buf)
	} else {
		log.Print(logContent)
	}

}

func Close() error {
	if writer != nil {
		if err := writer.Close(); err != nil {
			return err
		} else {
			writer = nil
		}
	}
	return nil
}
<commit_msg>do flush when run fatal method<commit_after>package glogger

import (
	"fmt"
	"log"
	"time"
	"os"
)

const (
	LevelDebug = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal

	defaultTimeFormat   = "2006-01-02 15:04:05"
	defaultformatString = "%s ▶ %.3s %s"
)

var (
	// higher means more serious, log level : DEBUG < INFO < WARN < ERROR < FATAL
	LevelName [5]string = [5]string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"}
	writer    *RotateLogger
)

func Debug(v ...interface{}) {
	output(LevelDebug, fmt.Sprintln(v...))
}

func Debugf(format string, v ...interface{}) {
	output(LevelDebug, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Info(v ...interface{}) {
	output(LevelInfo, fmt.Sprintln(v...))
}

func Infof(format string, v ...interface{}) {
	output(LevelInfo, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Warn(v ...interface{}) {
	output(LevelWarn, fmt.Sprintln(v...))
}

func Warnf(format string, v ...interface{}) {
	output(LevelWarn, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Error(v ...interface{}) {
	output(LevelError, fmt.Sprintln(v...))
}

func Errorf(format string, v ...interface{}) {
	output(LevelError, fmt.Sprintln(fmt.Sprintf(format, v...)))
}

func Fatal(v ...interface{}) {
	output(LevelFatal, fmt.Sprintln(v...))
	writer.Close()
	os.Exit(1)
}

func Fatalf(format string, v ...interface{}) {
	output(LevelFatal, fmt.Sprintln(fmt.Sprintf(format, v...)))
	writer.Close()
	os.Exit(1)
}

func Setup(path string, level int) error {
	var err error
	if writer, err = NewRotateLogger(path, level); err != nil {
		return err
	}
	return nil
}

func SetLevel(level int) {
	writer.SetLevel(level)
}

func Level(level int) int {
	return writer.Level()
}

func output(level int, content string) {
	if level < writer.Level() {
		return
	}

	//the writer may be close
	logContent := fmt.Sprintf(defaultformatString, time.Now().Format(defaultTimeFormat), LevelName[level], content)
	if writer != nil {
		buf := make([]byte, len(logContent))
		copy(buf, logContent)
		writer.Write(buf)
	} else {
		log.Print(logContent)
	}

}

func Close() error {
	if writer != nil {
		if err := writer.Close(); err != nil {
			return err
		} else {
			writer = nil
		}
	}
	return nil
}

{'fraction_non_alphanumeric': 0.17531718569780855, 'fraction_numerical': 0.008765859284890426, 'mean_word_length': 3.8285077951002227, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6733923', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1571, 'n_words': 383}