<commit_before>package logrusx

import (
	log "github.com/Sirupsen/logrus"
)

// DefaultSetup sets the logrus formatter and log level
func DefaultSetup(logLevel string) error {
	err := SetLevel(logLevel)
	if err != nil {
		return err
	}
	log.SetFormatter(&MistifyFormatter{})
	return nil
}

// SetLevel parses and sets the log level
func SetLevel(logLevel string) error {
	level, err := log.ParseLevel(logLevel)
	if err != nil {
		return err
	}
	log.SetLevel(level)
	return nil
}<commit_msg>Add LogReturnedErr convenience method<commit_after>package logrusx

import (
	log "github.com/Sirupsen/logrus"
)

// DefaultSetup sets the logrus formatter and log level
func DefaultSetup(logLevel string) error {
	err := SetLevel(logLevel)
	if err != nil {
		return err
	}
	log.SetFormatter(&MistifyFormatter{})
	return nil
}

// SetLevel parses and sets the log level
func SetLevel(logLevel string) error {
	level, err := log.ParseLevel(logLevel)
	if err != nil {
		return err
	}
	log.SetLevel(level)
	return nil
}

// LogReturnedErr wraps a function that returns an error, calls the function,
// and logs any error.
// Useful for basic defer, e.g. `defer LogReturnedErr(f.Close())`
func LogReturnedErr(fn func() error, fields log.Fields, message string) {
	if err := fn(); err != nil {
		if fields == nil {
			fields = log.Fields{}
		}
		fields["error"] = err
		log.WithFields(fields).Error(message)
	}
}
{'fraction_non_alphanumeric': 0.11023622047244094, 'fraction_numerical': 0.0, 'mean_word_length': 4.1208791208791204, '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': '1898026', 'n_tokens_mistral': 477, 'n_tokens_neox': 463, 'n_words': 144}