> For the complete documentation index, see [llms.txt](https://docs.buildings.ability.abb/collection/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.buildings.ability.abb/collection/german/plattform/platform-core/script-engine/writing-python-scripts/output-logging-and-error-handling.md).

# Protokollierung der Ausgabe und Fehlerbehandlung

## Übersicht

Beim Ausführen von Skripten im BuildingPro-Suites-System werden alle Ausgaben, wie z. B. `print` -Anweisungen, Informationen über die Ausführung und Fehler im **Grafana-Container (SSR)**. Jede Skriptausführung erhält eine eindeutige **Funktions-ID** , wodurch es möglich ist, die Ausgaben einzelner Skripte gezielt nachzuverfolgen. Dieser Leitfaden erklärt, wie solche Logeinträge aussehen können und was sie bedeuten.

## Wichtige Hinweise

### Sofortige Ausgabe mit `print` Anweisungen

Um sicherzustellen, dass `print` Ausgaben sofort sichtbar sind, verwenden Sie den Parameter **`flush=True`** in Ihren `print` Anweisungen. Dadurch wird verhindert, dass die Ausgabe im Puffer verbleibt, und stellt sicher, dass sie direkt im Log erscheint.

**Beispiel:**

```python
print("Ergebnis: 42", flush=True)
```

## Fehlerprotokollierung

Alle Fehler, die während der Ausführung eines Skripts auftreten, werden ebenfalls im Grafana-Log angezeigt. Durch geeignete Fehlerbehandlung können Sie sicherstellen, dass zusätzliche Details protokolliert werden, was die Fehlersuche erleichtert.

**Beispiel für Fehlerprotokollierung:**

```python
try:
    # Code, der Fehler verursachen könnte
except Exception as e:
    print(f"Ein Fehler ist aufgetreten: {e}", flush=True)
    raise
```

Durch die Verwendung von `flush=True` in Kombination mit einer umfassenden Fehlerbehandlung können Sie sicherstellen, dass alle wichtigen Informationen sofort im Log sichtbar sind und potenzielle Probleme schnell identifiziert und behoben werden können.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.buildings.ability.abb/collection/german/plattform/platform-core/script-engine/writing-python-scripts/output-logging-and-error-handling.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
