<commit_before>package conf

import (
	"os"
	"path"
	"path/filepath"
	"regexp"
	"runtime"
	"strconv"
	"strings"
	"time"

	"github.com/Sirupsen/logrus"
	beego "github.com/astaxie/beego/logs"
)

// GOPATH contains the gopath of the env
var GOPATH string

// LogDir is the log directory for logs.json
var LogDir string

// LogFile name
var LogFile string

func init() {
	GOPATH = os.Getenv("GOPATH")
	if GOPATH == "" {
		GOPATH = defaultGOPATH()
	}

	appPath := GOPATH + "/src/github.com/snagles/docker-registry-manager/app"
	LogDir = appPath + "/logs/"
	LogFile = LogDir + "/log.json"

	// Create the log file if needed
	if _, err := os.Stat(LogFile); os.IsNotExist(err) {
		if _, err = os.Create(LogFile); err != nil {
			logrus.Fatal(err)
		}
	}

	// Setup logrus
	f, _ := os.OpenFile(LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0755)
	logrus.SetOutput(f)
	logrus.SetFormatter(&logrus.JSONFormatter{})
	logrus.AddHook(ContextHook{})

	// Setup Beego logging by registering the hook
	beego.Register("docker-registry-manager", NewBeegoHook)
	beego.SetLogger("docker-registry-manager", "")
	beego.EnableFuncCallDepth(true)
}

type registryLogger struct {
	Level int `json:"level"`
}

func NewBeegoHook() beego.Logger { return &registryLogger{Level: 0} }<commit_msg>Create log dir if needed<commit_after>package conf

import (
	"os"
	"path"
	"path/filepath"
	"regexp"
	"runtime"
	"strconv"
	"strings"
	"time"

	"github.com/Sirupsen/logrus"
	beego "github.com/astaxie/beego/logs"
)

// GOPATH contains the gopath of the env
var GOPATH string

// LogDir is the log directory for logs.json
var LogDir string

// LogFile name
var LogFile string

func init() {
	GOPATH = os.Getenv("GOPATH")
	if GOPATH == "" {
		GOPATH = defaultGOPATH()
	}

	appPath := GOPATH + "/src/github.com/snagles/docker-registry-manager/app"
	LogDir = appPath + "/logs/"
	LogFile = LogDir + "/log.json"

	// create log dir if needed
	if _, err := os.Stat(LogDir); os.IsNotExist(err) {
		if err = os.Mkdir(LogDir, 0755); err != nil {
			logrus.Fatal(err)
		}
	}

	// Create the log file if needed
	if _, err := os.Stat(LogFile); os.IsNotExist(err) {
		if _, err = os.Create(LogFile); err != nil {
			logrus.Fatal(err)
		}
	}

	// Setup logrus
	f, _ := os.OpenFile(LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0755)
	logrus.SetOutput(f)
	logrus.SetFormatter(&logrus.JSONFormatter{})
	logrus.AddHook(ContextHook{})

	// Setup Beego logging by registering the hook
	beego.Register("docker-registry-manager", NewBeegoHook)
	beego.SetLogger("docker-registry-manager", "")
	beego.EnableFuncCallDepth(true)
}

type registryLogger struct {
	Level int `json:"level"`
}

func NewBeegoHook() beego.Logger { return &registryLogger{Level: 0} }
{'fraction_non_alphanumeric': 0.14349276974416017, 'fraction_numerical': 0.005190952910641453, 'mean_word_length': 4.024208566108007, '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': '7271989', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1017, 'n_words': 228}