# Logging

Logging is one of the foundational pieces of telemetry we need to understand issues at runtime. It is therefore deemed one of the core responsibilities of developers to provide meaningful logs.

## Logging infrastructure

Developers should use the `logging` library that is part of the monorepo and is configured for local as well as production environments. Don't use other methods of logging since that could lead to log statements not getting delivered correctly to the central log store.

## Logging levels

The logging levels to be used are `error`, `warn`,`info` and `debug`. Everything from level `info` and up (that's `info`, `error` and `warn`) are delivered to the central log store. You can use all the levels of course but the logs with logging level lower than `info` will be discarded when deployed to one of the environments. We can change the logging level for a specific service to a lower level but that is a manual operation, to be used only as a last resort.

Example - [logging](https://github.com/island-is/island.is/blob/main/apps/reference-backend/src/app/modules/resource/resource.service.ts#L31-L33)

## Viewing logs

You can search for and view the logs from all environments at [https://app.datadoghq.eu/logs](https://app.datadoghq.eu/logs?env=dev).

## Best practices

Use `error` when you are reporting errors or exceptions.

Use `warn` when things are in 'suspicious' or potentially problematic state.

Use `info` when reaching important states - server started, user created, registration complete, etc. or anything worth knowing about

Use `debug` for additional info.

Avoid logging at level `info` inside unbounded loops.

Don't log the same exception/error multiple times.

Do not log full personal identifiable or other sensitive information. User database IDs are preferred to users' names for example.


---

# 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.devland.is/development/devops/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.
