<commit_before>/*
Package log provides an logger that logs to the $LOG log file. If $LOG is not provided, stderr is used.
$LOGPREF is the logging prefix and $LOGFLG is the logging flag. If $LOGFLG isn't provided, log.LstdFlags is used.
See standard go log package for more info.
*/
package log

import (
	"fmt"
	golog "log"
	"os"
	"strconv"
)

var logger *golog.Logger

func init() {
	var (
		logFileName = os.Getenv("$LOG")
		logPref     = os.Getenv("$LOGPREF")
		logFlg      = os.Getenv("$LOGFLG")
		logFlgI     int
		logFile     *os.File
		openErr     error
		atoiErr     error
	)

	if logFileName != "" {
		logFile, openErr = os.Create(logFileName)
		if openErr != nil {
			logFile = os.Stderr
		}
	} else {
		logFile = os.Stderr
	}

	if logFlg != "" {
		logFlgI, atoiErr = strconv.Atoi(logFlg)
	}
	if logFlg == "" || atoiErr != nil {
		logFlgI = golog.LstdFlags
	}

	logger = golog.New(logFile, logPref, logFlgI)

	if openErr != nil {
		fmt.Printf("Error opening log file with Name: %v Error: %v\n", logFileName, openErr)
	}
	if atoiErr != nil {
		fmt.Printf("Bad Log Flag: %v Error: %v\n ", logFlg, atoiErr)
	}
}

/*
Logger returns the rns logger
*/
func Logger() *golog.Logger {
	return logger
}<commit_msg>Changed log from env config to using a Config function compatible with command line switch configuration.<commit_after>/*
Package log provides a configured instance of a log package logger that is shared within an executable.
Typically the executable will provide -log, -logpref and -logflg command line switches containing respectively the log file name, log prefix and log flag values.
The executable's init will parse these command line flags and then configure this log instance with them.

See standard go log package for more info.
*/
package log

import (
	golog "log"
	"os"
)

var logger *golog.Logger

/*
Config initializes the shared log instance. It should be called from an executable's init function. If it is not called, a default log instance that logs to os.Stderr is created.
*/
func Config(logname, logpref string, logflg int) {
	var (
		logFile *os.File
		openErr error
	)

	if logname != "" {
		logFile, openErr = os.Create(logname)
		if openErr != nil {
			logFile = os.Stderr
		}
	} else {
		logFile = os.Stderr
	}

	logger = golog.New(logFile, logpref, logflg)

	if openErr != nil {
		logger.Printf("Logging to stderr because opening log file with Name: %v failed with Error: %v\n", logname, openErr)
	}
}

/*
Logger returns the shared logger
*/
func Logger() *golog.Logger {
	if logger == nil {
		Config("", "", 0)
	}
	return logger
}
{'fraction_non_alphanumeric': 0.10303265940902022, 'fraction_numerical': 0.00038880248833592535, 'mean_word_length': 3.4592720970537263, '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': '3452790', 'n_tokens_mistral': 906, 'n_tokens_neox': 864, 'n_words': 321}