> 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).

# Ausgabeprotokollierung 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
