<commit_before>package ushare

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"ushare/core"
)

const GExecutableDirectory string = "bin"
const GConfigFileName string = "config.json"

var GConfig Config
var GDatabase Database

// ============ Public Functions ============

func InitEnv() error {
	log.Println("init environment: ...")
	if err := initWorkingDirectory(); err != nil {
		return err
	}

	log.Println("init logging: ...")
	if err := core.InitLogging(); err != nil {
		return err
	}

	log.Printf("init GConfig(%s)...", GConfigFileName)
	GConfig = Config{}
	if err := GConfig.Load(GConfigFileName); err != nil {
		return err
	}
	log.Println("GConfig initialized.")

	web_dir, _ := GConfig.LocateString("web_dir")
	if err := validateWebFolder(web_dir); err != nil {
		return err
	}
	log.Println("web directory validated: ", web_dir)

	db_addr, _ := GConfig.LocateString("db.addr")
	db_name, _ := GConfig.LocateString("db.name")
	log.Printf("connecting to db(addr:%s, name:%s)...", db_addr, db_name)
	if err := GDatabase.Connect(db_addr, db_name); err != nil {
		return err
	}
	log.Println("database connected.")<commit_msg>添加调试打印<commit_after>package ushare

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"ushare/core"
)

const GExecutableDirectory string = "bin"
const GConfigFileName string = "config.json"

var GConfig Config
var GDatabase Database

// ============ Public Functions ============

func InitEnv() error {
	log.Println("init environment: ...")
	if err := initWorkingDirectory(); err != nil {
		return err
	}

	log.Println("init logging: ...")
	if err := core.InitLogging(); err != nil {
		return err
	}

	log.Printf("init GConfig(%s)...", GConfigFileName)
	GConfig = Config{}
	if err := GConfig.Load(GConfigFileName); err != nil {
		return err
	}
	log.Println("GConfig initialized.")

	web_dir, _ := GConfig.LocateString("web_dir")
	core.LogDebug("web_dir: %s", web_dir)
	if wd, err := os.Getwd(); err == nil {
		core.LogDebug("working_dir: %s", wd)
	}
	if err := validateWebFolder(web_dir); err != nil {
		return err
	}
	log.Println("web directory validated: ", web_dir)

	db_addr, _ := GConfig.LocateString("db.addr")
	db_name, _ := GConfig.LocateString("db.name")
	log.Printf("connecting to db(addr:%s, name:%s)...", db_addr, db_name)
	if err := GDatabase.Connect(db_addr, db_name); err != nil {
		return err
	}
	log.Println("database connected.")
{'fraction_non_alphanumeric': 0.1771885521885522, 'fraction_numerical': 0.0, 'mean_word_length': 4.390022675736962, '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': '6934367', 'n_tokens_mistral': 880, 'n_tokens_neox': 855, 'n_words': 195}