# Logging

Copper provides the `clogger` package that allows structured logging in both dev and prod environments. It integrates deeply with `cerrors` to produce insightful logs with detailed error messages.

```go
err := s.starships.PropelRocket(ctx, "my-test-rocket")
if err != nil {
	s.logger.WithTags(map[string]any{
		"rocket": "my-test-rocket",
	}).Error("Failed to propel rocket", err)
}
```

The code snippet above may produce the following log statement:

```
Failed to propel rocket where rocket=my-test-rocket because
> failed to thrust engine where engine_number=3 because
> no more fuel where tank=1
```

Note that the errors are fully unwrapped, each providing a level of detail on what may have gone wrong. Since each error is tagged, we see helpful information like "engine\_number=3" and "tank=1".

{% hint style="info" %}
The logger can be configured to produce a multiline log statement for better readability or a JSON formatted single-line statement so that it can be easily parsed and indexed by log aggregators.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gocopper.gitbook.io/copper/core/logging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
