# Logging

### Overview <a href="#overview" id="overview"></a>

zeknd has built-in configurable logging. The user can configure the log level and the log destination.

### #zeknd SDK Logging <a href="#loom-sdk-logging" id="loom-sdk-logging"></a>

#### #Configuring the log level <a href="#configuring-the-log-level" id="configuring-the-log-level"></a>

The zeknd SDK provides two types of logs:

* blockchain logs (blockchain transactions and consensus events).
* zeknd SDK logs (generated by the SDK itself, i.e emitted events).

As an example, add the following to your zeknd`.yaml` to set logging levels:

```
zekndLogLevel: debug # sets the log level for events emitted from the zeknd SDK
BlockchainLogLevel: error # sets the log level for the blockchain logs.
```

> Defaults for the zeknd`LogLevel` and `BlockchainLogLevel` are `info` and `error` respectively.

#### #Configuring the log destination <a href="#configuring-the-log-destination" id="configuring-the-log-destination"></a>

Currently, a file target is supported for the zeknd logs:

```
LogDestination: "file://zeknd.log" # zeknd.log is also the default target.
```

To log to stderr, specify the destination as `file://-`

### #Contract logging <a href="#contract-logging" id="contract-logging"></a>

Configurations like log level and destination are separate for contracts. These are set using environment variables.

Example: `CONTRACT_LOG_LEVEL=debug CONTRACT_LOG_DESTINATION="file://-" $`zeknd`_EXE run`

This will set the contract log level to `debug` and the destination to stderr.

The default for log level and destination are `info` and `file://contract.log` respectively.

#### #Logging from the contract <a href="#logging-from-the-contract" id="logging-from-the-contract"></a>

The contract context has a pre-configured logger that can be used for structured logging. Let's look at an example:

```
ctx.Logger().Info("Created account", "owner", owner, "address", addr)
```

will generate a log line like:

```
ts=2018-05-13T02:06:49.817229589Z module=zeknd level=info _msg="Created account" owner=godbole4 address="\ufffd8\ufffd\ufffd\ufffd\ufffd\ufffd$Y+H\ufffd\u0012\u000c]\u001a\ufffd\ufffd\ufffd\ufffd"
```

Available methods on the context logger are `Error`, `Warn`, `Info`, and `Debug`.

<br>

<br>


---

# 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://developer.opzeknd.xyz/monitoring/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.
