<commit_before>package runner

import (
	"bufio"
	"io"

	"github.com/Sirupsen/logrus"
)

// FuncLogger reads STDERR output from a container and outputs it in a parseable structured log format, see: https://github.com/iron-io/functions/issues/76
type FuncLogger struct {
	r io.Reader
	w io.Writer
}

func NewFuncLogger(appName, path, function, requestID string) io.Writer {
	r, w := io.Pipe()
	funcLogger := &FuncLogger{
		r: r,
		w: w,
	}
	log := logrus.WithFields(logrus.Fields{"app_name": appName, "path": path, "function": function, "request_id": requestID})
	go func(reader io.Reader) {
		scanner := bufio.NewScanner(reader)
		for scanner.Scan() {
			log.Println(scanner.Text())
		}
		if err := scanner.Err(); err != nil {
			log.WithError(err).Println("There was an error with the scanner in attached container")
		}
	}(r)
	return funcLogger
}

func (l *FuncLogger) Write(p []byte) (n int, err error) {
	return l.w.Write(p)
}<commit_msg>Added user_log=true to user log lines.<commit_after>package runner

import (
	"bufio"
	"io"

	"github.com/Sirupsen/logrus"
)

// FuncLogger reads STDERR output from a container and outputs it in a parseable structured log format, see: https://github.com/iron-io/functions/issues/76
type FuncLogger struct {
	r io.Reader
	w io.Writer
}

func NewFuncLogger(appName, path, function, requestID string) io.Writer {
	r, w := io.Pipe()
	funcLogger := &FuncLogger{
		r: r,
		w: w,
	}
	log := logrus.WithFields(logrus.Fields{"user_log": true, "app_name": appName, "path": path, "function": function, "request_id": requestID})
	go func(reader io.Reader) {
		scanner := bufio.NewScanner(reader)
		for scanner.Scan() {
			log.Println(scanner.Text())
		}
		if err := scanner.Err(); err != nil {
			log.WithError(err).Println("There was an error with the scanner in attached container")
		}
	}(r)
	return funcLogger
}

func (l *FuncLogger) Write(p []byte) (n int, err error) {
	return l.w.Write(p)
}
{'fraction_non_alphanumeric': 0.14218993253762324, 'fraction_numerical': 0.0020757654385054488, 'mean_word_length': 4.224932249322493, 'pattern_counts': {'":': 9, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2055631', 'n_tokens_mistral': 721, 'n_tokens_neox': 687, 'n_words': 193}