improved logging
This commit is contained in:
parent
f8407162ad
commit
05b41cedce
81 changed files with 9802 additions and 279 deletions
|
|
@ -5,15 +5,16 @@ package scan
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/fs"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/log"
|
||||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/fs"
|
||||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -44,13 +45,14 @@ var (
|
|||
)
|
||||
|
||||
type Scanner struct {
|
||||
log logr.Logger
|
||||
base string
|
||||
timeout time.Duration
|
||||
t Tesseract
|
||||
p PDF
|
||||
}
|
||||
|
||||
func New(c *core.Config) (s *Scanner, err error) {
|
||||
func New(log logr.Logger, c *core.Config) (s *Scanner, err error) {
|
||||
var (
|
||||
tcmd string
|
||||
pcmd string
|
||||
|
|
@ -92,6 +94,7 @@ func New(c *core.Config) (s *Scanner, err error) {
|
|||
}
|
||||
args := []string{"-l", lang, "--oem", fmt.Sprintf("%d", c.TesseractOEM)}
|
||||
s = &Scanner{
|
||||
log,
|
||||
c.DataDir,
|
||||
time.Second * time.Duration(c.CMDTimeout),
|
||||
Tesseract{tcmd, args, []string{fmt.Sprintf("OMP_THREAD_LIMIT=%d", threads)}},
|
||||
|
|
@ -101,6 +104,7 @@ func New(c *core.Config) (s *Scanner, err error) {
|
|||
}
|
||||
|
||||
func (s *Scanner) Scan(file string) (filename, text string, err error) {
|
||||
log := s.log
|
||||
file = fs.Clean(file)
|
||||
scanfile := filepath.Join(s.base, file)
|
||||
var pdffile string
|
||||
|
|
@ -117,7 +121,7 @@ func (s *Scanner) Scan(file string) (filename, text string, err error) {
|
|||
p, _ := filepath.Split(file)
|
||||
pdfCmd := exec.Command(s.t.cmd, append(s.t.args, []string{scanfile, "stdout", "pdf"}...)...)
|
||||
pdfCmd.Env = s.t.env
|
||||
log.Debugf("%v %s %v", pdfCmd.Env, pdfCmd.Path, pdfCmd.Args)
|
||||
log.V(2).Info("tesseract command", "env", pdfCmd.Env, "path", pdfCmd.Path, "args", pdfCmd.Args)
|
||||
pdf, err = timeout(pdfCmd, s.timeout)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -140,7 +144,7 @@ func (s *Scanner) Scan(file string) (filename, text string, err error) {
|
|||
filename = file
|
||||
}
|
||||
txtCmd := exec.Command(s.p.cmd, append(s.p.args, []string{pdffile, "-"}...)...)
|
||||
log.Debugf("%s %v", txtCmd.Path, txtCmd.Args)
|
||||
log.V(2).Info("text2pdf command", "path", txtCmd.Path, "args", txtCmd.Args)
|
||||
txt, err := timeout(txtCmd, s.timeout)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue