<commit_before>package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/op/go-logging"
	"golang.org/x/net/websocket"

	"github.com/microscaling/microscaling/api"
	"github.com/microscaling/microscaling/demand"
	"github.com/microscaling/microscaling/engine"
	"github.com/microscaling/microscaling/engine/localEngine"
	"github.com/microscaling/microscaling/engine/serverEngine"
	"github.com/microscaling/microscaling/scheduler"
	"github.com/microscaling/microscaling/scheduler/docker"
	"github.com/microscaling/microscaling/scheduler/marathon"
	"github.com/microscaling/microscaling/scheduler/toy"
)

type settings struct {
	schedulerType string
	sendMetrics   bool
	userID        string
	pullImages    bool
	dockerHost    string
	demandEngine  string
	marathonAPI   string
}

func initLogging() {
	// The MSS_LOG_DEBUG environment variable controls what logging is output
	// By default the log level is INFO for all components
	// Adding a component name to MSS_LOG_DEBUG makes its logging level DEBUG
	// In addition, if "detail" is included in the environment variable details of the process ID and file name / line number are included in the logs
	// MSS_LOG_DEBUG="all" - turn on DEBUG for all components
	// MSS_LOG_DEBUG="mssapi,detail" - turn on DEBUG for the api package, and use the detailed logging format
	basicLogFormat := logging.MustStringFormatter(`%{color}%{level:.4s} %{time:15:04:05.000}: %{color:reset} %{message}`)
	detailLogFormat := logging.MustStringFormatter(`%{color}%{level:.4s} %{time:15:04:05.000} %{pid} %{shortfile}: %{color:reset} %{message}`)

	logComponents := getEnvOrDefault("MSS_LOG_DEBUG", "none")
	if strings.Contains(logComponents, "detail") {
		logging.SetFormatter(detailLogFormat)
	} else {
		logging.SetFormatter(basicLogFormat)
	}

	logBackend := logging.NewLogBackend(os.Stdout, "", 0)
	logging.SetBackend(logBackend)

	var components = []string{"mssengine", "mssagent", "mssapi", "mssdemand", "mssmetric", "mssscheduler", "msstarget"}

	for _, component := range components {
		if strings.Contains(logComponents, component) || strings.Contains(logComponents, "all") {
			logging.SetLevel(logging.DEBUG, component)
		} else {
			logging.SetLevel(logging.INFO, component)
		}
	}
}

func getSettings() settings {
	var st settings
	st.schedulerType = getEnvOrDefault("MSS_SCHEDULER", "DOCKER")
	st.userID = getEnvOrDefault("MSS_USER_ID", "5k5gk")
	st.sendMetrics = (getEnvOrDefault("MSS_SEND_METRICS_TO_API", "true") == "true")
	st.pullImages = (getEnvOrDefault("MSS_PULL_IMAGES", "true") == "true")
	st.dockerHost = getEnvOrDefault("DOCKER_HOST", "unix:///var/run/docker.sock")
	st.demandEngine = getEnvOrDefault("MSS_DEMAND_ENGINE", "SERVER")
	st.marathonAPI = getEnvOrDefault("MSS_MARATHON_API", "http://localhost:8080")
	return st<commit_msg>Default engine to local not server since random metric is deprecated.<commit_after>package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/op/go-logging"
	"golang.org/x/net/websocket"

	"github.com/microscaling/microscaling/api"
	"github.com/microscaling/microscaling/demand"
	"github.com/microscaling/microscaling/engine"
	"github.com/microscaling/microscaling/engine/localEngine"
	"github.com/microscaling/microscaling/engine/serverEngine"
	"github.com/microscaling/microscaling/scheduler"
	"github.com/microscaling/microscaling/scheduler/docker"
	"github.com/microscaling/microscaling/scheduler/marathon"
	"github.com/microscaling/microscaling/scheduler/toy"
)

type settings struct {
	schedulerType string
	sendMetrics   bool
	userID        string
	pullImages    bool
	dockerHost    string
	demandEngine  string
	marathonAPI   string
}

func initLogging() {
	// The MSS_LOG_DEBUG environment variable controls what logging is output
	// By default the log level is INFO for all components
	// Adding a component name to MSS_LOG_DEBUG makes its logging level DEBUG
	// In addition, if "detail" is included in the environment variable details of the process ID and file name / line number are included in the logs
	// MSS_LOG_DEBUG="all" - turn on DEBUG for all components
	// MSS_LOG_DEBUG="mssapi,detail" - turn on DEBUG for the api package, and use the detailed logging format
	basicLogFormat := logging.MustStringFormatter(`%{color}%{level:.4s} %{time:15:04:05.000}: %{color:reset} %{message}`)
	detailLogFormat := logging.MustStringFormatter(`%{color}%{level:.4s} %{time:15:04:05.000} %{pid} %{shortfile}: %{color:reset} %{message}`)

	logComponents := getEnvOrDefault("MSS_LOG_DEBUG", "none")
	if strings.Contains(logComponents, "detail") {
		logging.SetFormatter(detailLogFormat)
	} else {
		logging.SetFormatter(basicLogFormat)
	}

	logBackend := logging.NewLogBackend(os.Stdout, "", 0)
	logging.SetBackend(logBackend)

	var components = []string{"mssengine", "mssagent", "mssapi", "mssdemand", "mssmetric", "mssscheduler", "msstarget"}

	for _, component := range components {
		if strings.Contains(logComponents, component) || strings.Contains(logComponents, "all") {
			logging.SetLevel(logging.DEBUG, component)
		} else {
			logging.SetLevel(logging.INFO, component)
		}
	}
}

func getSettings() settings {
	var st settings
	st.schedulerType = getEnvOrDefault("MSS_SCHEDULER", "DOCKER")
	st.userID = getEnvOrDefault("MSS_USER_ID", "5k5gk")
	st.sendMetrics = (getEnvOrDefault("MSS_SEND_METRICS_TO_API", "true") == "true")
	st.pullImages = (getEnvOrDefault("MSS_PULL_IMAGES", "true") == "true")
	st.dockerHost = getEnvOrDefault("DOCKER_HOST", "unix:///var/run/docker.sock")
	st.demandEngine = getEnvOrDefault("MSS_DEMAND_ENGINE", "LOCAL")
	st.marathonAPI = getEnvOrDefault("MSS_MARATHON_API", "http://localhost:8080")
	return st
{'fraction_non_alphanumeric': 0.1289693099166223, 'fraction_numerical': 0.009579563597658328, 'mean_word_length': 5.586448598130841, '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': '2424988', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1844, 'n_words': 391}