diff --git a/.gitignore b/.gitignore index 3b1931e..29df7c6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # Custom Additions servtex -servtex.log -output +*.aux +*.log +*.pdf diff --git a/backend/backend.go b/backend/backend.go index 7b4ad1e..018dba7 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -7,8 +7,8 @@ import ( "os" "os/exec" "path/filepath" + "strings" "time" - "git.noctra.dev/noctra/servtex/globals" ) @@ -32,8 +32,16 @@ func GetLocalTimePretty() string { return GetLocalTime().Format("02.01.2006 15:04") } -// Writes to log and prints to screen -func LogLine(message string) { +// Writes to log file and prints to screen +// +// Levels: +// 1 - Debug +// 2 - Info +// 3 - Warning +// 4 - Error +func LogLine(message string, level int) { + if level < globals.AppConfig.LogLevelNumeric { return } + logline := GetLocalTimeLog() + " ServTeX: " + message + "\n" fmt.Print(logline) globals.LogFile.WriteString(logline) @@ -46,15 +54,31 @@ func configReaderParse(filePath string, configOptionStorage *globals.Config) err jsonData, err := os.ReadFile(filePath) if err == nil { if err = json.Unmarshal(jsonData, &configOptionStorage); err != nil { + LogLine("Configuration file is invaldi JSON", 5) return errors.New("Config file could not be read") } } else { + LogLine(fmt.Sprintf("Config at %s does not exist", filePath), 1) return errors.New("Config file does not exist") } + switch strings.ToLower(configOptionStorage.LogLevel) { + case "debug": + configOptionStorage.LogLevelNumeric = 1 + case "info": + configOptionStorage.LogLevelNumeric = 2 + case "warning": + configOptionStorage.LogLevelNumeric = 3 + case "error": + configOptionStorage.LogLevelNumeric = 4 + default: + configOptionStorage.LogLevelNumeric = 3 + LogLine("Defaulting to log level warning", 3) + } return configValidator(*configOptionStorage) } +// tbd what exactly happens here func configValidator(config globals.Config) error { return nil } @@ -91,7 +115,7 @@ func ConfigReader(configFileName string, configOptionStorage *globals.Config) er // // Optionally, a minimum time to wait for consecutive changes can be specified func ChangeWatch(path string, callOnChange func()) { - LogLine("File change noticed") + LogLine("File change noticed", 2) } // Intended to be run as goroutine @@ -99,11 +123,11 @@ func LatexCompile(config globals.Config, execution *globals.LatexExecution) erro if execution.ExecutionLock.TryLock() { defer execution.ExecutionLock.Unlock() } else { - LogLine("LaTeX execution already underway") + LogLine("LaTeX execution already underway", 2) return errors.New("Execution already in progress") } - LogLine("LaTeX execution started") + LogLine("LaTeX execution started", 2) execution.ExecutionState = "Started" var latexCommand *exec.Cmd @@ -115,11 +139,13 @@ func LatexCompile(config globals.Config, execution *globals.LatexExecution) erro "-jobname=servtex", config.LatexSourceFilePath, ) + LogLine(fmt.Sprintf("Command: %s", latexCommand.String()), 1) default: execution.ExecutionState = "Unknown Latex Engine" execution.Output = []byte{} execution.Timestamp = GetLocalTimePretty() - return errors.New("Unknown Latex Engine") + LogLine("Unsupported LaTeX Engine", 4) + return errors.New("Unsupported LaTeX Engine") } execution.ExecutionState = "Running" @@ -132,6 +158,7 @@ func LatexCompile(config globals.Config, execution *globals.LatexExecution) erro execution.Output = stdout execution.Timestamp = GetLocalTimePretty() execution.ExecutionState = "Done" + LogLine("LaTeX execution finished", 2) return nil } diff --git a/config.json b/config.json index 3f2632c..d079421 100644 --- a/config.json +++ b/config.json @@ -3,14 +3,14 @@ "logFilePath": "./servtex.log", "latexEngine": "lualatex", - "latexSourceFilePath": "", - "latexOutputPath": "./output", + "latexSourceFilePath": "./testfiles/Example.tex", + "latexOutputPath": "./testfiles/output", "webserverDomain": "localhost", "webserverPort": "8080", "webserverSecure": true, "webserverPortSecure": "8443", - "certificatePath": "./testing.crt", - "certificateKeyPath": "./testing.key", + "certificatePath": "./testfiles/tls/testing.crt", + "certificateKeyPath": "./testfiles/tls/testing.key", "timezone": "Europe/Berlin" } diff --git a/frontend/jscss/custom-view.css b/frontend/jscss/custom-view.css index e08e099..45d2a7a 100644 --- a/frontend/jscss/custom-view.css +++ b/frontend/jscss/custom-view.css @@ -3,6 +3,7 @@ } .left-sidebar { padding: 15px; + height: 100%; } .pdf-frame { width: 100%; diff --git a/frontend/templates/main.html b/frontend/templates/main.html index c2ce990..86b0666 100644 --- a/frontend/templates/main.html +++ b/frontend/templates/main.html @@ -12,26 +12,23 @@
-