> For the complete documentation index, see [llms.txt](https://ecm-pmdm-flutter.gitbook.io/1.-introduccion-a-flutter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ecm-pmdm-flutter.gitbook.io/1.-introduccion-a-flutter/3.-primera-aplicacion-en-flutter/herramientas-para-debugging.-logs.md).

# Herramientas para debugging. Logs

{% hint style="info" %}
Más información en: <https://docs.flutter.dev/testing/code-debugging>&#x20;
{% endhint %}

Para realizar **debugging** de las aplicaciones Flutter tenemos variedad de herramientas:

* [DevTools](https://docs.flutter.dev/development/tools/devtools), suite de herramientas de rendimiento y profiling disponibles **desde** el **navegador**.
* [Android Studio/IntelliJ](https://docs.flutter.dev/development/tools/android-studio#run-app-with-breakpoints), y [VS Code](https://docs.flutter.dev/development/tools/vs-code#run-app-with-breakpoints) (con los plugins de Flutter y Dart ) permiten **depuración** del código con ***breakpoints***, ejecución paso a paso, inspeccionar variables,..etc.
* [Flutter inspector](https://docs.flutter.dev/development/tools/devtools/inspector), disponible en las **DevTools** y también directamente en el **IDE** Android Studio/IntelliJ (Flutter/Dart plugin).  El inspector nos permite examinar visualmente el widget tree, inspeccionar propiedades concretas de widgets, ...etc.

## Logs <a href="#devtools" id="devtools"></a>

Podemos registrar **mensajes** **de** **log** para realizar **debugging** **desde** el **código**.  &#x20;

Luego, podremos verlos:&#x20;

* Desde la pestaña "**Logging** **View"** de las **Devtools** o el **Logcat**
* Directamente en la **consola**.

Tenemos dos **opciones**:

1. Llamar directamente a la función **`print('my_message')`**  de `dart:core` que imprimirà el mensaje en la Consola.  En Logcat se registrará del tipo `Info`:  "`I/flutter (11714)   :` ".&#x20;

> Si "my\_message"  es muy largo, puede ser **truncado** por el sistema operativo, en ese caso, es mejor utilizar **`debugPrint("my_message")`** de  `package:flutter/foundation.dart'` que no trunca la salida.   En cualquier caso, deberían eliminarse siempre antes de la versión release.

```dart
import 'package:flutter/foundation.dart';

// Salida simple, puede ser truncada si es muy larga.
print("Esto es una respuesta de API larga: {...}");
// Salida controlada, no se truncará.
debugPrint("Esto es una respuesta de API larga: {...}");
```

2. Utilizar la función **`log()`**  de  `dart:developer` que nos permite **estructurar** mejor la información de *log*.  Estos mensajes de log,  nunca se incluyen al compilar la versión release.

```dart
void log(
  String message, {
  DateTime? time,
  int? sequenceNumber,
  int level = 0,
  String name = '',
  Zone? zone,
  Object? error,
  StackTrace? stackTrace,
});
```

{% hint style="info" %}
**Valor de Level → Nivel en Logcat de Android:**\
level < 800 (FINE, CONFIG, etc.)     V  (Verbose) o D (Debug)\
level >= 800 y < 900 (INFO)              I    (Info)\
level >= 900 y < 1000                         W   (Warning) \
level >= 1000 (SEVERE, SHOUT)     E   (Error)
{% endhint %}

**Ejemplo**:

```dart
import 'dart:convert';
import 'dart:developer' as developer;

void main() {
    developer.log(
    'Main started',
    name: 'main()',
    level: 900,  // Logcat: Warning
  );
}
```


---

# 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://ecm-pmdm-flutter.gitbook.io/1.-introduccion-a-flutter/3.-primera-aplicacion-en-flutter/herramientas-para-debugging.-logs.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.
