Skip to content

Commit 4de192f

Browse files
committed
Re-visit logging
boxes and glue takes does not change the slog default logger anymore. You need to initialize the logger by using the function bag.SetLogger(*slog.Logger) to get log output.
1 parent 293b2eb commit 4de192f

File tree

9 files changed

+25
-26
lines changed

9 files changed

+25
-26
lines changed

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ task :build do
3333
sh "go build -ldflags \"-X github.com/speedata/xts/core.Version=#{@xts_version}\" -o bin/xts github.com/speedata/xts/xts"
3434
end
3535

36+
desc "Update markdown documentation"
3637
task "doc" => [:xtshelper] do
3738
sh "#{installdir}/bin/xtshelper doc"
3839
puts "done"

core/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ func cmdTd(xd *xtsDocument, layoutelt *goxml.Element) (xpath.Sequence, error) {
18881888
case *html.Node:
18891889
td.AppendChild(t)
18901890
default:
1891-
slog.Error(fmt.Sprintf("Unknown item type", t))
1891+
slog.Error(fmt.Sprintf("Unknown item type %T", t))
18921892
}
18931893
}
18941894
return xpath.Sequence{td}, nil

core/core.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func RunXTS(cfg *XTSConfig) error {
200200
if d.document, err = frontend.New(cfg.OutFilename); err != nil {
201201
return err
202202
}
203+
bag.SetLogger(slog.Default())
203204
if cfg.SuppressInfo {
204205
d.document.SetSuppressInfo(true)
205206
slog.Info("Creating reproducible build")

core/functions.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ import (
1515
"strconv"
1616
"strings"
1717

18-
"golang.org/x/exp/slog"
19-
2018
"github.com/alecthomas/chroma/formatters/html"
2119
"github.com/speedata/boxesandglue/backend/bag"
2220
"github.com/speedata/goxpath"
2321
"github.com/yuin/goldmark"
2422
highlighting "github.com/yuin/goldmark-highlighting"
2523
"github.com/yuin/goldmark/extension"
24+
"golang.org/x/exp/slog"
2625
)
2726

2827
const fnNS = "urn:speedata.de/2021/xtsfunctions/en"

core/page.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package core
33
import (
44
"fmt"
55

6-
"golang.org/x/exp/slog"
7-
86
"github.com/speedata/boxesandglue/backend/bag"
97
"github.com/speedata/boxesandglue/backend/document"
108
"github.com/speedata/boxesandglue/backend/node"
119
"github.com/speedata/boxesandglue/frontend"
1210
"github.com/speedata/goxml"
11+
"golang.org/x/exp/slog"
1312
)
1413

1514
const (
@@ -29,7 +28,7 @@ type pagetype struct {
2928
}
3029

3130
func (xd *xtsDocument) newPagetype(name string, test string) (*pagetype, error) {
32-
slog.Info(fmt.Sprintf("Define new page type %q", name))
31+
slog.Info("Define new page type", "type", name)
3332
pt := &pagetype{
3433
name: name,
3534
test: test,

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ require (
77
github.com/cjoudrey/gluahttp v0.0.0-20201111170219-25003d9adfa9
88
github.com/mitchellh/mapstructure v1.5.0
99
github.com/pelletier/go-toml/v2 v2.0.8
10-
github.com/speedata/bagme v0.0.0-20230623185222-e07a73460716
10+
github.com/speedata/bagme v0.0.0-20230717123802-85d3038669b2
1111
github.com/speedata/barcode v0.0.0-20230307084753-486c4d51cb34
12-
github.com/speedata/baseline-pdf v0.0.0-20230715152647-532f2af918e1
13-
github.com/speedata/boxesandglue v0.0.0-20230715153045-5eacf0f3bb41
12+
github.com/speedata/baseline-pdf v0.0.0-20230717121810-fcb08a486045
13+
github.com/speedata/boxesandglue v0.0.0-20230717123135-dd440b2c55c7
1414
github.com/speedata/goxlsx v1.0.2
1515
github.com/speedata/goxml v0.0.0-20230322084327-216af189a791
1616
github.com/speedata/goxpath v0.0.0-20230709190058-ca75de231e9c
@@ -19,7 +19,7 @@ require (
1919
github.com/yuin/goldmark v1.4.13
2020
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594
2121
github.com/yuin/gopher-lua v1.1.0
22-
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
22+
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
2323
golang.org/x/net v0.10.0
2424
golang.org/x/sys v0.8.0
2525
golang.org/x/text v0.9.0

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZ
2121
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
2222
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2323
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
24-
github.com/speedata/bagme v0.0.0-20230623185222-e07a73460716 h1:fIbB6r6OSsye4oTmt8c2RbhSThKDgmO7NY4B4XBn+vA=
25-
github.com/speedata/bagme v0.0.0-20230623185222-e07a73460716/go.mod h1:2z4dHmmUCQcF9kNVeC+67jaUBQ+qR70gI1135Quaxd8=
24+
github.com/speedata/bagme v0.0.0-20230717123802-85d3038669b2 h1:jEx978p/smBVb6HvA8ywaJLwIKQ5JjWIdi3j+qu0RCA=
25+
github.com/speedata/bagme v0.0.0-20230717123802-85d3038669b2/go.mod h1:CB2a0wR8k15CcTnZ4CorC+kbhQMQEIs3Dnp3KpGaHHI=
2626
github.com/speedata/barcode v0.0.0-20230307084753-486c4d51cb34 h1:FeXq9Yh4eiH+dqkWW/HVzXhLghaNoXxzLG+tjdlduYw=
2727
github.com/speedata/barcode v0.0.0-20230307084753-486c4d51cb34/go.mod h1:BNwJ2io3ZgecUqunSUFAlfnnI8YTh3SLSHZgs5vaoTY=
28-
github.com/speedata/baseline-pdf v0.0.0-20230715152647-532f2af918e1 h1:8vIGIoA21bWxTZrJjS6EGFlgmAcAHbPRW9CrK4CwdCU=
29-
github.com/speedata/baseline-pdf v0.0.0-20230715152647-532f2af918e1/go.mod h1:ptfWHTOg/v3zstZUxF9DwET4q4NOMCGyzDvtm11SIWs=
30-
github.com/speedata/boxesandglue v0.0.0-20230715153045-5eacf0f3bb41 h1:A6Ik7Jd4BR2Up6g15jCHFXfun7TwcOyuYiBC/jqt50Y=
31-
github.com/speedata/boxesandglue v0.0.0-20230715153045-5eacf0f3bb41/go.mod h1:4tyX1Or3K2JL3NmhnBl0+SJgVeLC7gE4xOo368NJOq0=
28+
github.com/speedata/baseline-pdf v0.0.0-20230717121810-fcb08a486045 h1:u/GYT64cM/P+Xr8V/bafekZ5LMiKGl8JrGq9Aybrn5s=
29+
github.com/speedata/baseline-pdf v0.0.0-20230717121810-fcb08a486045/go.mod h1:QASGTrWm543HeZkydj6uZubpXhV7vUkuKwVJethlwD0=
30+
github.com/speedata/boxesandglue v0.0.0-20230717123135-dd440b2c55c7 h1:XJz1sxw0Lulj9VSxLelqD3ePgXgDH/u7tnTXYf7UMJU=
31+
github.com/speedata/boxesandglue v0.0.0-20230717123135-dd440b2c55c7/go.mod h1:8MKBdJtdN9mMfVqKvbi6cuU6Towco6s0eSD317Wa7k0=
3232
github.com/speedata/css/scanner v0.0.0-20201005071706-2ed32c3ce553 h1:L9Sqi5S7G4JjODI5tZZ1IzZ7Yb4s71xFOq/uZtLv1Wg=
3333
github.com/speedata/css/scanner v0.0.0-20201005071706-2ed32c3ce553/go.mod h1:uF4+EGySaBnGeZpXZ0boh/oR6P0vNiYfQ2MAJXCU9hE=
3434
github.com/speedata/gofpdi v1.0.18 h1:LEiIN62ckZcA4n8AtBu16M2P2fBK3OnwpTGDfe13v/4=
@@ -62,8 +62,8 @@ github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE
6262
github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
6363
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
6464
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
65-
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us=
66-
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
65+
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw=
66+
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
6767
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
6868
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
6969
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=

xts/logging.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010
"strings"
1111

12-
"github.com/speedata/boxesandglue/backend/bag"
1312
"github.com/speedata/xts/core"
1413
"golang.org/x/exp/slog"
1514
)
@@ -23,6 +22,7 @@ var (
2322
protocolFile io.Writer
2423
errCount = 0
2524
warnCount = 0
25+
loglevel slog.LevelVar
2626
)
2727

2828
type logHandler struct {
@@ -34,7 +34,7 @@ func (lh *logHandler) Enabled(_ context.Context, level slog.Level) bool {
3434
} else if level == slog.LevelWarn {
3535
warnCount++
3636
}
37-
return level >= bag.LogLevel.Level()
37+
return level >= loglevel.Level()
3838
}
3939

4040
func (lh *logHandler) Handle(_ context.Context, r slog.Record) error {

xts/main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"time"
1515

1616
"github.com/pelletier/go-toml/v2"
17-
"github.com/speedata/boxesandglue/backend/bag"
1817
"github.com/speedata/optionparser"
1918
"github.com/speedata/textlayout/fonts/truetype"
2019
"github.com/speedata/xts/core"
@@ -289,15 +288,15 @@ func dothings() error {
289288

290289
switch configuration.LogLevel {
291290
case "debug":
292-
bag.LogLevel.Set(slog.LevelDebug)
291+
loglevel.Set(slog.LevelDebug)
293292
case "info":
294-
bag.LogLevel.Set(slog.LevelInfo)
293+
loglevel.Set(slog.LevelInfo)
295294
case "notice":
296-
bag.LogLevel.Set(core.LevelNotice)
295+
loglevel.Set(core.LevelNotice)
297296
case "warn":
298-
bag.LogLevel.Set(slog.LevelWarn)
297+
loglevel.Set(slog.LevelWarn)
299298
case "error":
300-
bag.LogLevel.Set(slog.LevelError)
299+
loglevel.Set(slog.LevelError)
301300
}
302301

303302
if configuration.Quiet {

0 commit comments

Comments
 (0)