<commit_before>package logformatter

import (
	"encoding/json"
	"fmt"

	"github.com/Sirupsen/logrus"
	"os"
	"time"
)

// LogstashFormatter generates json in logstash format.
// Logstash site: http://logstash.net/
type LogstashFormatter struct {

	//Type of the fields
	Type string // if not empty use for logstash type field.

	//Env is the environment on which the application is running
	Env string

	//ServiceName will be by default guble
	ServiceName string

	//ApplicationType will be  by default "service".Other values could be "service", "system", "appserver", "webserver"
	ApplicationType string

	//LogType will be by default  application.Other possible values "access", "error", "application", "system"
	LogType string

	// TimestampFormat sets the format used for timestamps.
	TimestampFormat string

	// Host  sets the host field
	Host string
}

// Format the logrus entry to a byte slice, or return an error.
func (f *LogstashFormatter) Format(entry *logrus.Entry) ([]byte, error) {
	fields := make(logrus.Fields)
	for k, v := range entry.Data {
		fields[k] = v
	}

	timeStampFormat := f.TimestampFormat
	if timeStampFormat == "" {
		timeStampFormat = time.RFC3339<commit_msg>Added host in the logs<commit_after>package logformatter

import (
	"encoding/json"
	"fmt"

	"github.com/Sirupsen/logrus"
	"os"
	"time"
)

// LogstashFormatter generates json in logstash format.
// Logstash site: http://logstash.net/
type LogstashFormatter struct {

	//Type of the fields
	Type string // if not empty use for logstash type field.

	//Env is the environment on which the application is running
	Env string

	//ServiceName will be by default guble
	ServiceName string

	//ApplicationType will be  by default "service".Other values could be "service", "system", "appserver", "webserver"
	ApplicationType string

	//LogType will be by default  application.Other possible values "access", "error", "application", "system"
	LogType string

	// TimestampFormat sets the format used for timestamps.
	TimestampFormat string
}

// Format the logrus entry to a byte slice, or return an error.
func (f *LogstashFormatter) Format(entry *logrus.Entry) ([]byte, error) {
	fields := make(logrus.Fields)
	for k, v := range entry.Data {
		fields[k] = v
	}

	timeStampFormat := f.TimestampFormat
	if timeStampFormat == "" {
		timeStampFormat = time.RFC3339
{'fraction_non_alphanumeric': 0.0990183525394793, 'fraction_numerical': 0.0034144259496372174, 'mean_word_length': 4.040860215053764, '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': '1538096', 'n_tokens_mistral': 745, 'n_tokens_neox': 715, 'n_words': 262}