<commit_before>package papertrail

import (
	"bytes"
	"time"

	"github.com/vektra/addons/lib/tcplog"
	"github.com/vektra/components/lib/request"
	"github.com/vektra/cypress"
)

const cTimeFormat = time.RFC3339Nano
const cNewline = "\n"

type PapertrailFormatter struct{}

func NewLogger(address string, ssl bool) *tcplog.Logger {
	return tcplog.NewLogger(address, ssl, &PapertrailFormatter{})
}

func (pf *PapertrailFormatter) Format(m *cypress.Message) ([]byte, error) {
	var buf bytes.Buffer

	time := m.GetTimestamp().Time().Format(cTimeFormat)

	buf.WriteString(time)
	buf.WriteString(" ")

	if s := m.GetSessionId(); len(s) > 0 {
		buf.WriteString(request.Id(s).String()[0:7])
	} else {
		buf.WriteString("0000000")
	}

	// Special case the logs that come out of the volts to make them easier to read
	if m.GetType() == 0 {
		if volt, ok := m.GetString("volt"); ok {
			if log, ok := m.GetString("log"); ok {

				buf.WriteString(" ")
				buf.WriteString(volt)
				buf.WriteString(" ")
				buf.WriteString(log)
				buf.WriteString(cNewline)

				return buf.Bytes(), nil
			}
		}
	}

	buf.WriteString(" system ")<commit_msg>Replace request with oss uuid<commit_after>package papertrail

import (
	"bytes"
	"time"

	"github.com/vektra/addons/lib/tcplog"
	"github.com/vektra/cypress"
	"github.com/vektra/uuid"
)

const cTimeFormat = time.RFC3339Nano
const cNewline = "\n"

type PapertrailFormatter struct{}

func NewLogger(address string, ssl bool) *tcplog.Logger {
	return tcplog.NewLogger(address, ssl, &PapertrailFormatter{})
}

func (pf *PapertrailFormatter) Format(m *cypress.Message) ([]byte, error) {
	var buf bytes.Buffer

	time := m.GetTimestamp().Time().Format(cTimeFormat)

	buf.WriteString(time)
	buf.WriteString(" ")

	if s := m.GetSessionId(); len(s) > 0 {
		buf.WriteString(uuid.Id(s).String()[0:7])
	} else {
		buf.WriteString("0000000")
	}

	// Special case the logs that come out of the volts to make them easier to read
	if m.GetType() == 0 {
		if volt, ok := m.GetString("volt"); ok {
			if log, ok := m.GetString("log"); ok {

				buf.WriteString(" ")
				buf.WriteString(volt)
				buf.WriteString(" ")
				buf.WriteString(log)
				buf.WriteString(cNewline)

				return buf.Bytes(), nil
			}
		}
	}

	buf.WriteString(" system ")
{'fraction_non_alphanumeric': 0.1528209684584629, 'fraction_numerical': 0.01332741003998223, 'mean_word_length': 3.9933481152993346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '481916', 'n_tokens_mistral': 912, 'n_tokens_neox': 825, 'n_words': 180}