create output directory before scan, added loglevel 'fatal'
This commit is contained in:
parent
fdbc3a1561
commit
c53a2c2e72
3 changed files with 15 additions and 2 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -9,7 +9,7 @@
|
||||||
"program": "${workspaceFolder}/main.go",
|
"program": "${workspaceFolder}/main.go",
|
||||||
"env": {
|
"env": {
|
||||||
"GO_SCAN_SCANNER": "utsushi:esci:usb:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0",
|
"GO_SCAN_SCANNER": "utsushi:esci:usb:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0",
|
||||||
"GO_SCAN_OUTPUTDIRECTORY": "/tmp",
|
"GO_SCAN_OUTPUTDIRECTORY": "/tmp/scans",
|
||||||
"GO_SCAN_ARGUMENTS": "--jpeg-quality 100 --mode Color --scan-area ISO/A4/Portrait --resolution 600"
|
"GO_SCAN_ARGUMENTS": "--jpeg-quality 100 --mode Color --scan-area ISO/A4/Portrait --resolution 600"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"velvettear/go-scan/util/date"
|
"velvettear/go-scan/util/date"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,6 +23,11 @@ func Error(logMessage string, logExtras ...string) {
|
||||||
trace(3, logMessage, logExtras...)
|
trace(3, logMessage, logExtras...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Fatal(logMessage string, logExtras ...string) {
|
||||||
|
trace(4, logMessage, logExtras...)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// unexported functions
|
// unexported functions
|
||||||
func trace(logLevel int, logMessage string, logExtras ...string) {
|
func trace(logLevel int, logMessage string, logExtras ...string) {
|
||||||
if len(logMessage) == 0 {
|
if len(logMessage) == 0 {
|
||||||
|
@ -46,6 +52,8 @@ func trace(logLevel int, logMessage string, logExtras ...string) {
|
||||||
|
|
||||||
func getPrefixForLogLevel(loglevel int) string {
|
func getPrefixForLogLevel(loglevel int) string {
|
||||||
switch loglevel {
|
switch loglevel {
|
||||||
|
case 4:
|
||||||
|
return "fatal"
|
||||||
case 3:
|
case 3:
|
||||||
return "error"
|
return "error"
|
||||||
case 2:
|
case 2:
|
||||||
|
|
7
main.go
7
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -33,7 +34,7 @@ func startServer() {
|
||||||
log.Info("starting server '" + serverAddress + "'...")
|
log.Info("starting server '" + serverAddress + "'...")
|
||||||
error := http.ListenAndServe(serverAddress, nil)
|
error := http.ListenAndServe(serverAddress, nil)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
log.Error("an error occured starting the server", error.Error())
|
log.Fatal("an error occured starting the server", error.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +145,10 @@ func generateScanName(filename string) string {
|
||||||
if !strings.HasSuffix(filename, ".png") {
|
if !strings.HasSuffix(filename, ".png") {
|
||||||
filename += ".png"
|
filename += ".png"
|
||||||
}
|
}
|
||||||
|
error := os.MkdirAll(configuration.ScannerConfig.OutputDirectory, 0755)
|
||||||
|
if error != nil {
|
||||||
|
log.Fatal("an error occurred creating the output directory", error.Error())
|
||||||
|
}
|
||||||
return configuration.ScannerConfig.OutputDirectory + filename
|
return configuration.ScannerConfig.OutputDirectory + filename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue