<commit_before>package log

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	logger "github.com/inconshreveable/log15"
	"github.com/k0kubun/pp"
)

// SetLogger set logger
func SetLogger(logDir string, quiet, debug, logJSON bool) {
	stderrHundler := logger.StderrHandler
	logFormat := logger.LogfmtFormat()
	if logJSON {
		logFormat = logger.JsonFormatEx(false, true)
		stderrHundler = logger.StreamHandler(os.Stderr, logFormat)
	}

	lvlHundler := logger.LvlFilterHandler(logger.LvlInfo, stderrHundler)
	if debug {
		lvlHundler = logger.LvlFilterHandler(logger.LvlDebug, stderrHundler)
	}
	if quiet {
		lvlHundler = logger.LvlFilterHandler(logger.LvlDebug, logger.DiscardHandler())
		pp.SetDefaultOutput(ioutil.Discard)
	}

	if _, err := os.Stat(logDir); os.IsNotExist(err) {
		if err := os.Mkdir(logDir, 0700); err != nil {
			logger.Error("Failed to create log directory", "err", err)
		}
	}
	var hundler logger.Handler
	if _, err := os.Stat(logDir); err == nil {
		logPath := filepath.Join(logDir, "cve-dictionary.log")
		hundler = logger.MultiHandler(
			logger.Must.FileHandler(logPath, logFormat),
			lvlHundler,
		)
	} else {
		hundler = lvlHundler<commit_msg>fix(logger): panic if no file permission #153 (#154)<commit_after>package log

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	logger "github.com/inconshreveable/log15"
	"github.com/k0kubun/pp"
)

// SetLogger set logger
func SetLogger(logDir string, quiet, debug, logJSON bool) {
	stderrHundler := logger.StderrHandler
	logFormat := logger.LogfmtFormat()
	if logJSON {
		logFormat = logger.JsonFormatEx(false, true)
		stderrHundler = logger.StreamHandler(os.Stderr, logFormat)
	}

	lvlHundler := logger.LvlFilterHandler(logger.LvlInfo, stderrHundler)
	if debug {
		lvlHundler = logger.LvlFilterHandler(logger.LvlDebug, stderrHundler)
	}
	if quiet {
		lvlHundler = logger.LvlFilterHandler(logger.LvlDebug, logger.DiscardHandler())
		pp.SetDefaultOutput(ioutil.Discard)
	}

	if _, err := os.Stat(logDir); os.IsNotExist(err) {
		if err := os.Mkdir(logDir, 0700); err != nil {
			logger.Error("Failed to create a log directory", "err", err)
		}
	}
	var hundler logger.Handler
	if _, err := os.Stat(logDir); err == nil {
		logPath := filepath.Join(logDir, "cve-dictionary.log")
		if err := ioutil.WriteFile(logPath, []byte{}, 0700); err != nil {
			logger.Error("Failed to create a log file", "err", err)
			hundler = lvlHundler
		} else {
			hundler = logger.MultiHandler(
				logger.Must.FileHandler(logPath, logFormat),
				lvlHundler,
			)
		}

	} else {
		hundler = lvlHundler
{'fraction_non_alphanumeric': 0.13194988253719656, 'fraction_numerical': 0.009397024275646046, 'mean_word_length': 4.447761194029851, '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': '1614127', 'n_tokens_mistral': 1036, 'n_tokens_neox': 967, 'n_words': 189}