For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/dart-code-quality/avoid-print.md. A documentation index is available at /llms.txt.
This product is not supported for your selected Datadog site. ().

Metadata

ID: dart-code-quality/avoid-print

Language: Dart

Severity: Notice

Category: Code Style

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

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

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

Compliant Code Examples

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);
  }
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security