<commit_before>package logger

//----------------------------------------------------------------------
// This file is part of Gospel.
// Copyright (C) 2011-2020 <NAME>
//
// Gospel is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Gospel is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: AGPL3.0-or-later
//----------------------------------------------------------------------

import (
	"fmt"
	"time"
)

// Formatter function type: convert a log message into a string for output
type Formatter func(msg *logMsg) string

// SimpleFormat creates a plain format for log messages
func SimpleFormat(msg *logMsg) string {
	ts := msg.ts.Format(time.Stamp)
	lvl := getTag(msg.level)
	txt := msg.text
	pos := len(txt) - 1
	for txt[pos] == '\n' {
		txt = txt[:pos]
		pos--
	}
	return fmt.Sprintf("%s [%s] %s", ts, lvl, txt)
}

// ColorFormat uses colors for different log levels
func ColorFormat(msg *logMsg) string {
	col := 34 // light blue for undef`d levels
	switch msg.level {
	case CRITICAL:
		col = 31
	case ERROR:
		col = 31
	case WARN:
		col = 33
	case INFO:
		col = 37
	case DBG:
		col = 90
	}
	txt := SimpleFormat(msg)
	return fmt.Sprintf("\033[01;%dm%s\033[01;0m\n", col, txt)<commit_msg>Strip line-breaks from message and insert line-break in output.<commit_after>package logger

//----------------------------------------------------------------------
// This file is part of Gospel.
// Copyright (C) 2011-2020 <NAME>
//
// Gospel is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Gospel is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: AGPL3.0-or-later
//----------------------------------------------------------------------

import (
	"fmt"
	"strings"
	"time"
)

// Formatter function type: convert a log message into a string for output
type Formatter func(msg *logMsg) string

// SimpleFormat creates a plain format for log messages
func SimpleFormat(msg *logMsg) string {
	ts := msg.ts.Format(time.Stamp)
	lvl := getTag(msg.level)
	txt := msg.text

	txt = strings.Trim(txt, "\n")
	return fmt.Sprintf("%s [%s] %s\n", ts, lvl, txt)
}

// ColorFormat uses colors for different log levels
func ColorFormat(msg *logMsg) string {
	col := 34 // light blue for undef`d levels
	switch msg.level {
	case CRITICAL:
		col = 31
	case ERROR:
		col = 31
	case WARN:
		col = 33
	case INFO:
		col = 37
	case DBG:
		col = 90
	}
	txt := SimpleFormat(msg)
	txt = strings.Trim(txt, "\n")
	return fmt.Sprintf("\033[01;%dm%s\033[01;0m\n", col, txt)
{'fraction_non_alphanumeric': 0.18334264952487422, 'fraction_numerical': 0.019284516489659027, 'mean_word_length': 2.4347408829174664, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6226189', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1037, 'n_words': 433}