# Logging

## Introduction

Logging is built-in with ConanJs to provide you with an integrated platform so that you can:

* Log meaningful message easily
* Log what is happening internally in ConanJs
* Fine tune at runtime what should be logged.

ConanData and Asaps both produce ConanJs log messages out of the box.

{% hint style="success" %}
As of v1.0 dependency injection does not log anything at the moment, but this will be the case soon.
{% endhint %}

## Anatomy

A logging message has many attributes that are helpful to understand where the message comes from, its information, and also, to make easier to fine tune what should be logged out.

### Nature (Where?)

Indicates the nature of the source of this log message. There are seven natures:

| Name       | Source                                                                                                                             |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| **MAIN**   | The [main thread](/data/conan-state/life-cycle.md#the-main-thread) in a Conan state                                                |
| **META**   | The [meta flow](/data/conan-state/life-cycle.md#the-meta-flow) in a Conan state                                                    |
| **ASYNC**  | The [monitor thread](/data/conan-state/life-cycle.md#the-monitor-thread) in a Conan state                                          |
| **HELPER** | The [main thread](/data/conan-state/life-cycle.md#the-main-thread) in a Conan state (when the user decides to override the nature) |
| **ASAP**   | Log message from an [ASAP](/asaps.md).                                                                                             |
| **AUX**    | Derived from a Conan State that is created internally by the framework (you are likely to want to have this always turned off)     |

### Level (How important?)

There are 7 levels. In order of importance (from less important to more important):

* **DEBUG**
* **TRACE**
* **INFO**
* **MILESTONE**
* **WARN**
* **ERROR**

### shortDesc

A string message describing what is happening

### payload

Optionally, there can a payload that will also get logged out.

## Fine tuning Logging.

You can configure what to log at runtime. By default it gets log out everything that is:

**MAIN** and **MILESTONE**

To fine tune what gets logged out there are three main methods

#### updateLoggingFilter

Receives the current rules for logging, returns the new rules for logging

#### setLoggingFilter

Sets the logging rules

#### getLoggingFilter

Get the current rules.

## Demo

The following example illustrates how to change the logging levels at runtime

{% embed url="<https://codesandbox.io/s/2dqbx>" %}


---

# 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://docs.conanjs.io/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.
