<commit_before>package logSys

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

type MsgType uint8

const (
	Message  MsgType = 0
	Message2 MsgType = 1
	Warning  MsgType = 2
	Debug    MsgType = 3
	Error    MsgType = 0x80
)

var DebugMode = false

func Println(m MsgType, msg ...interface{}) {
	if m == Debug && !DebugMode {
		return
	}

	var debugInfo string
	var color string
	var prefix string

	switch m {
	case Message:
		color = "\x1b[37m" // White
		prefix = "msg"
	case Message2:
		color = "\x1b[92m" // Light green
		prefix = "msg"
	case Warning:
		color = "\x1b[93m" // Light Yellow
		prefix = "warning"
	case Debug:
		color = "\x1b[96m" // Light Cyan
		prefix = "debug"
	case Error:
		color = "\x1b[91m" // Light Red
		prefix = "error"
	}

	if DebugMode {
		_, fn, line, _ := runtime.Caller(1)
		fn = filepath.Base(fn)
		debugInfo = fmt.Sprintf("%s:%d ", fn, line)
	}

	fmt.Printf("%s%s [%s] %s%s\033[0;00m\n",<commit_msg>split the code and improves the interface<commit_after>package log

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

type msgType uint8

// DebugMode Enable debug mode
var DebugMode bool

const (
	messageConst  msgType = 0
	message2Const msgType = 1
	warningConst  msgType = 2
	debugConst    msgType = 3
	errorConst    msgType = 0x80
)

/*
TODO: Create a more flexible HTTP error return as an example below
func HTTPError(w http.ResponseWriter, code int) {
	msg := http.StatusText(code)
	pln(errorConst, msg)
	m := make(map[string]string)
	m["status"] = "error"
	m["error"] = msg
	b, _ := json.MarshalIndent(m, "", "\t")
	http.Error(w, string(b), code)
}
*/

// Fatal show message with line break at the end and exit to OS.
func Fatal(msg ...interface{}) {
	pln(errorConst, msg...)
	os.Exit(-1)
}

// Errorln message with line break at the end.
func Errorln(msg ...interface{}) {
	pln(errorConst, msg...)
}

// Println shows message on screen with line break at the end.
func Println(msg ...interface{}) {
	pln(messageConst, msg...)
}

// Debugln shows debug message on screen with line break at the end.
// If debug mode is not active no message is displayed
func Debugln(msg ...interface{}) {
	pln(debugConst, msg...)
}

func pln(m msgType, msg ...interface{}) {
	if m == debugConst && !DebugMode {
		return
	}

	var debugInfo string
	var color string
	var prefix string

	switch m {
	case messageConst:
		color = "\x1b[37m" // White
		prefix = "msg"
	case message2Const:
		color = "\x1b[92m" // Light green
		prefix = "msg"
	case warningConst:
		color = "\x1b[93m" // Light Yellow
		prefix = "warning"
	case debugConst:
		color = "\x1b[96m" // Light Cyan
		prefix = "debug"
	case errorConst:
		color = "\x1b[91m" // Light Red
		prefix = "error"
	}

	if DebugMode {
		_, fn, line, _ := runtime.Caller(2)
		fn = filepath.Base(fn)
		debugInfo = fmt.Sprintf("%s:%d ", fn, line)
	}

	fmt.Printf("%s%s [%s] %s%s\033[0;00m\n",
{'fraction_non_alphanumeric': 0.14275766016713093, 'fraction_numerical': 0.022632311977715876, 'mean_word_length': 3.206442166910688, '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': '4167033', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1074, 'n_words': 324}