Logging the optimization process | image-optimizer-go | Spatie       

 SPATIE  

image-optimizer-go
==================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Image-optimizer-go](https://spatie.be/docs/image-optimizer-go/v1)  Logging the optimization process

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/image-optimizer-go/v1) 

  Logging the optimization process    
- [ Introduction ](https://spatie.be/docs/image-optimizer-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/image-optimizer-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/image-optimizer-go/v1/usage)
- [ Which tools will do what? ](https://spatie.be/docs/image-optimizer-go/v1/which-tools-will-do-what)
- [ Logging the optimization process ](https://spatie.be/docs/image-optimizer-go/v1/logging-the-optimization-process)
- [ Example conversions ](https://spatie.be/docs/image-optimizer-go/v1/example-conversions)
- [ Testing ](https://spatie.be/docs/image-optimizer-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/image-optimizer-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/image-optimizer-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/image-optimizer-go/v1/support-us)

 Logging the optimization process
================================

By default the package operates silently and logs optimizer errors to a discard logger. To verify what the package is doing you can set a logger:

```
chain := imageoptimizer.New()
chain.Logger = slog.New(slog.NewTextHandler(os.Stderr, nil))
err := chain.Optimize(ctx, "image.jpg")
```

The logger is a standard Go `*slog.Logger`. The package logs which optimizers are used, which commands are executed, their combined output, and any optimizer errors. The same logger is passed to custom optimizers.

Paths, command arguments and process output may contain sensitive information. Configure a `slog.Handler` that redacts these fields if needed. Setting a logger does not enable strict errors. Use `chain.Throws` or `chain.OnError` separately.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
