---
title: Avoid using print() for logging
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid using print() for logging
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Avoid using print() for logging

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `dart-code-quality/avoid-print`

**Language:** Dart

**Severity:** Notice

**Category:** Code Style

## Description{% #description %}

print() writes directly to the console and is intended for debugging, not production logging. Using print() can expose sensitive information, provides no log levels or filtering, and cannot be silenced in release builds. Replace print() calls with a structured logging solution such as dart:developer's log() or a dedicated logging package.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dart
void main() {
    print('Server started');

    final value = 42;
    print('Value: $value');
  }
```

## Compliant Code Examples{% #compliant-code-examples %}

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

  class Logger {
    void print(String message, {String name = '', int level = 0}) {
      developer.log(message, name: name, level: level);
    }
  }

  void main() {
    developer.log('Server started', name: 'init', level: 800);
    final logger = Logger();
    logger.print('hello', name: 'greet', level: 500);
  }
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 