# Logging

## Overview

Logging is essential to any application, providing critical insights into its behavior, aiding debugging, and ensuring seamless monitoring in production environments. Othentic CLI features a robust logging system, offering flexibility to log multiple destinations.

## Log Levels

Logs are categorized by severity levels to help identify and filter specific types of messages:

* **info**: General information about the application’s operation.
* **debug**: Detailed information for debugging purposes. (included **only** in logs written to a file or sent to Elastic)
* **warn**: Indications of potential issues.
* **error**: Critical errors affecting the application.

## Logging Destinations

Othentic CLI supports the following destinations:

### **1. Console** (default):

Logs are printed directly to the standard output (stdout).

Example:

```log
[2025-01-14 19:12:49] [info] Submitting task signed by operators: 1
[2025-01-21 19:30:49] [warn] Failed to connect to peer 12D3KooWEsKHAZtWxBzqtHazZZN9vgnVo8bewpS6Vwfckub64jiV: TimeoutError: The operation was aborted due to timeout
[2025-01-14 19:13:17] [error] Server not running
```

### **2. File**:

Logs are written to rotating files in JSON format, making them ideal for historical log analysis and archiving.

Example log entry:

<pre class="language-log"><code class="lang-log"><strong>{
</strong><strong>  "timestamp":"2025-01-14 19:00:25",
</strong>  "version":"1.7.0",
  "level":"info",
  "context":"P2P",
  "message":"Connected to peer: 12D3KooWCVRxMBPYMSk1QNyasXgrTyMbHWGHftAWQRGrWzkGj2Ly"
}
</code></pre>

{% hint style="info" %}
**Configuration:**\
Add the following property to your `.env` file to specify the log directory:

```bash
LOG_DIR=<directory-path>
```

{% endhint %}

### **3. Elasticsearch**:

Logs are sent to an Elasticsearch instance for storage and advanced analytics.&#x20;

This is particularly useful in distributed environments where monitoring and querying logs is essential.

{% hint style="info" %}
**Configuration:**\
Add these elasticsearch properties to your `.env` file:

```bash
ELASTIC_URL=<elasticsearch-url>
ELASTIC_USERNAME=<username>
ELASTIC_PASSWORD=<password>
```

{% endhint %}

***

## Enable Debug logs

To enable detailed debug logs, add the following to your `.env` file:

```
# DEBUG=*
DEBUG=othentic:* // For all the logs except p2p
```

This will activate verbose logging for all internal Stack components and services.

***

## Recommendations for Use

* **Development**: Use the console destination for real-time feedback.
* **Production**:
  * Configure file-based logging for historical data and compliance requirements.
  * Use Elasticsearch for advanced monitoring and visualization with tools like Kibana.

{% hint style="info" %}
For distributed setups, use the [Elastic stack (ELK) on Docker](https://github.com/deviantony/docker-elk) to configure and run Elastic stack on docker.
{% endhint %}

By leveraging logging capabilities, you can clearly understand the application's operations and quickly address any issues.
