diff --git a/d2cli/main.go b/d2cli/main.go index 68ea60b42..52f3a2ed0 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -37,6 +37,7 @@ import ( "oss.terrastruct.com/d2/lib/pdf" "oss.terrastruct.com/d2/lib/png" "oss.terrastruct.com/d2/lib/pptx" + "oss.terrastruct.com/d2/lib/simplelog" "oss.terrastruct.com/d2/lib/textmeasure" timelib "oss.terrastruct.com/d2/lib/time" "oss.terrastruct.com/d2/lib/version" @@ -749,10 +750,11 @@ func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opts } cacheImages := ms.Env.Getenv("IMG_CACHE") == "1" - svg, bundleErr := imgbundler.BundleLocal(ctx, svg, cacheImages) + l := simplelog.FromCmdLog(ms.Log) + svg, bundleErr := imgbundler.BundleLocal(ctx, l, svg, cacheImages) if bundle { var bundleErr2 error - svg, bundleErr2 = imgbundler.BundleRemote(ctx, svg, cacheImages) + svg, bundleErr2 = imgbundler.BundleRemote(ctx, l, svg, cacheImages) bundleErr = multierr.Combine(bundleErr, bundleErr2) } if forceAppendix && !toPNG { @@ -765,7 +767,7 @@ func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opts if !bundle { var bundleErr2 error - svg, bundleErr2 = imgbundler.BundleRemote(ctx, svg, cacheImages) + svg, bundleErr2 = imgbundler.BundleRemote(ctx, l, svg, cacheImages) bundleErr = multierr.Combine(bundleErr, bundleErr2) } @@ -835,8 +837,9 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opt } cacheImages := ms.Env.Getenv("IMG_CACHE") == "1" - svg, bundleErr := imgbundler.BundleLocal(ctx, svg, cacheImages) - svg, bundleErr2 := imgbundler.BundleRemote(ctx, svg, cacheImages) + l := simplelog.FromCmdLog(ms.Log) + svg, bundleErr := imgbundler.BundleLocal(ctx, l, svg, cacheImages) + svg, bundleErr2 := imgbundler.BundleRemote(ctx, l, svg, cacheImages) bundleErr = multierr.Combine(bundleErr, bundleErr2) if bundleErr != nil { return svg, bundleErr @@ -936,8 +939,9 @@ func renderPPTX(ctx context.Context, ms *xmain.State, presentation *pptx.Present } cacheImages := ms.Env.Getenv("IMG_CACHE") == "1" - svg, bundleErr := imgbundler.BundleLocal(ctx, svg, cacheImages) - svg, bundleErr2 := imgbundler.BundleRemote(ctx, svg, cacheImages) + l := simplelog.FromCmdLog(ms.Log) + svg, bundleErr := imgbundler.BundleLocal(ctx, l, svg, cacheImages) + svg, bundleErr2 := imgbundler.BundleRemote(ctx, l, svg, cacheImages) bundleErr = multierr.Combine(bundleErr, bundleErr2) if bundleErr != nil { return nil, bundleErr @@ -1182,8 +1186,9 @@ func renderPNGsForGIF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plug } cacheImages := ms.Env.Getenv("IMG_CACHE") == "1" - svg, bundleErr := imgbundler.BundleLocal(ctx, svg, cacheImages) - svg, bundleErr2 := imgbundler.BundleRemote(ctx, svg, cacheImages) + l := simplelog.FromCmdLog(ms.Log) + svg, bundleErr := imgbundler.BundleLocal(ctx, l, svg, cacheImages) + svg, bundleErr2 := imgbundler.BundleRemote(ctx, l, svg, cacheImages) bundleErr = multierr.Combine(bundleErr, bundleErr2) if bundleErr != nil { return nil, nil, bundleErr diff --git a/lib/imgbundler/imgbundler.go b/lib/imgbundler/imgbundler.go index 8324ce205..08488df10 100644 --- a/lib/imgbundler/imgbundler.go +++ b/lib/imgbundler/imgbundler.go @@ -19,7 +19,7 @@ import ( "golang.org/x/xerrors" - "oss.terrastruct.com/d2/lib/log" + "oss.terrastruct.com/d2/lib/simplelog" "oss.terrastruct.com/util-go/xdefer" ) @@ -29,12 +29,12 @@ const maxImageSize int64 = 1 << 25 // 33_554_432 var imageRegex = regexp.MustCompile(` 0 { @@ -150,7 +150,7 @@ func runWorkers(ctx context.Context, svg []byte, imgs [][][]byte, isRemote, cach } } -func worker(ctx context.Context, href []byte, isRemote, cacheImages bool) ([]byte, error) { +func worker(ctx context.Context, l simplelog.Logger, href []byte, isRemote, cacheImages bool) ([]byte, error) { if cacheImages { if hit, ok := imgCache.Load(string(href)); ok { return hit.([]byte), nil @@ -160,10 +160,10 @@ func worker(ctx context.Context, href []byte, isRemote, cacheImages bool) ([]byt var mimeType string var err error if isRemote { - log.Debug(ctx, fmt.Sprintf("fetching %s remotely", string(href))) + l.Debug(fmt.Sprintf("fetching %s remotely", string(href))) buf, mimeType, err = httpGet(ctx, html.UnescapeString(string(href))) } else { - log.Debug(ctx, fmt.Sprintf("reading %s from disk", string(href))) + l.Debug(fmt.Sprintf("reading %s from disk", string(href))) buf, err = os.ReadFile(html.UnescapeString(string(href))) } if err != nil { diff --git a/lib/imgbundler/imgbundler_test.go b/lib/imgbundler/imgbundler_test.go index ae381636d..a8ebe37cd 100644 --- a/lib/imgbundler/imgbundler_test.go +++ b/lib/imgbundler/imgbundler_test.go @@ -16,6 +16,7 @@ import ( tassert "github.com/stretchr/testify/assert" "oss.terrastruct.com/d2/lib/log" + "oss.terrastruct.com/d2/lib/simplelog" ) //go:embed test_png.png @@ -96,7 +97,8 @@ width="328" height="587" viewBox="-100 -131 328 587"> `, svgURL, pngURL) - out, err := BundleLocal(ctx, []byte(sampleSVG), false) + l := simplelog.FromLibLog(ctx) + out, err := BundleLocal(ctx, l, []byte(sampleSVG), false) if err != nil { t.Fatal(err) } @@ -251,7 +254,8 @@ width="328" height="587" viewBox="-100 -131 328 587">