<commit_before>package Common

// 每日滚动的LOG实现

import (
	"fmt"
	"os"
	"path/filepath"
	"runtime"
	"sync"
	"time"
)

var (
	logDir  = os.TempDir()
	logDay  = 0
	logLock = sync.Mutex{}
	logFile *os.File
)

// parse env ENABLE_DEBUG_LOG and DISABLE_INFO_LOG
func init() {
	if proc, err := filepath.Abs(os.Args[0]); err == nil {
		SetLogDir(filepath.Dir(proc))
	}
}

func SetLogDir(dir string) {
	logDir = dir
}

func check() {
	logLock.Lock()
	defer logLock.Unlock()

	if logDay == time.Now().Day() {
		return
	}

	logDay = time.Now().Day()
	logFile.Sync()
	logFile.Close()
	logProc := filepath.Base(os.Args[0])
	filename := filepath.Join(logDir,
		fmt.Sprintf("%s.%s.log", logProc, time.Now().Format("2006-01-02")))
	var err error
	logFile, err = os.OpenFile(filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err != nil {
		logFile = os.Stderr
		fmt.Fprintln(os.Stderr, "check log file", err, "use STDOUT")
	}
}

func DropLog(v ...interface{}) {}

func DebugLog(v ...interface{}) {
	check()
	logLock.Lock()
	defer logLock.Unlock()
	_, file, line, _ := runtime.Caller(2)
	fmt.Fprintln(logFile, NumberNow(), file, line, "debug", v)
}

func InfoLog(v ...interface{}) {
	check()
	logLock.Lock()
	defer logLock.Unlock()
	_, file, line, _ := runtime.Caller(2)
	fmt.Fprintln(logFile, NumberNow(), file, line, "info", v)
}

func ErrorLog(v ...interface{}) {
	check()
	logLock.Lock()
	defer logLock.Unlock()
	_, file, line, _ := runtime.Caller(2)
	fmt.Fprintln(logFile, NumberNow(), file, line, "error", v)
}<commit_msg>log use short file name<commit_after>package Common

// 每日滚动的LOG实现

import (
	"fmt"
	"os"
	"path/filepath"
	"runtime"
	"sync"
	"time"
)

var (
	logDir  = os.TempDir()
	logDay  = 0
	logLock = sync.Mutex{}
	logFile *os.File
)

// parse env ENABLE_DEBUG_LOG and DISABLE_INFO_LOG
func init() {
	if proc, err := filepath.Abs(os.Args[0]); err == nil {
		SetLogDir(filepath.Dir(proc))
	}
}

func SetLogDir(dir string) {
	logDir = dir
}

func check() {
	logLock.Lock()
	defer logLock.Unlock()

	if logDay == time.Now().Day() {
		return
	}

	logDay = time.Now().Day()
	logFile.Sync()
	logFile.Close()
	logProc := filepath.Base(os.Args[0])
	filename := filepath.Join(logDir,
		fmt.Sprintf("%s.%s.log", logProc, time.Now().Format("2006-01-02")))
	var err error
	logFile, err = os.OpenFile(filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err != nil {
		logFile = os.Stderr
		fmt.Fprintln(os.Stderr, NumberNow(), "check log file", err, "use STDOUT")
	}
}

func DropLog(v ...interface{}) {}

func DebugLog(v ...interface{}) {
	check()
	logLock.Lock()
	defer logLock.Unlock()
	_, file, line, _ := runtime.Caller(1)
	fmt.Fprintln(logFile, NumberNow(), filepath.Base(file), line, "debug", v)
}

func InfoLog(v ...interface{}) {
	check()
	logLock.Lock()
	defer logLock.Unlock()
	_, file, line, _ := runtime.Caller(1)
	fmt.Fprintln(logFile, NumberNow(), filepath.Base(file), line, "info", v)
}

func ErrorLog(v ...interface{}) {
	check()
	logLock.Lock()
	defer logLock.Unlock()
	_, file, line, _ := runtime.Caller(1)
	fmt.Fprintln(logFile, NumberNow(), filepath.Base(file), line, "error", v)
}
{'fraction_non_alphanumeric': 0.18463524854744998, 'fraction_numerical': 0.011620400258231117, 'mean_word_length': 4.088669950738916, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6132625', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1259, 'n_words': 263}