Skip to main content

dart_auto_logger 1.1.0 copy "dart_auto_logger: ^1.1.0" to clipboard
dart_auto_logger: ^1.1.0 copied to clipboard

Automatic debug logging for Dart (Appwrite functions). Pure Dart with no Flutter dependencies.

dart_auto_logger #

Pure Dart debug logging for Appwrite functions and other Dart runtimes. No Flutter dependencies.

Goal #

100% complete logging — every single thing that happens should be logged so that when something goes wrong, you can debug and fix it entirely by reading the logs without needing to reproduce the issue or add more logging.

Installation #

dependencies:
  dart_auto_logger: ^1.0.0

Quick Start #

Appwrite Functions (wraps entire execution):

import 'package:dart_auto_logger/dart_auto_logger.dart';

Future<dynamic> main(final context) async {
  return DartAutoLogger.runDart(() async {
    // All HTTP, errors, timers automatically logged
    final response = await http.get(Uri.parse('https://api.example.com'));
    return context.res.json({'status': response.statusCode});
  });
}

CLI / Server Apps (initialize without zone wrapping):

import 'package:dart_auto_logger/dart_auto_logger.dart';

void main() {
  DartAutoLogger.initDart();
  // Logger is now active — HTTP, file I/O, errors all logged
}

runDart() vs initDart(): runDart() wraps code in a logging zone providing timer tracking, slow callback detection, print capture, and zone-based error catching. initDart() only sets up HTTP and file I/O overrides. Use runDart() when possible (Appwrite functions, short-lived scripts). Use initDart() for long-running servers where zone wrapping isn't practical.

What's Logged Automatically #

Category Type
HTTP requests ✅ Auto
File operations ✅ Auto
Socket connections ✅ Auto
Timers ✅ Auto
Errors/crashes ✅ Auto
Print statements ✅ Auto
Slow callbacks ✅ Auto
Drift SQL ✅ Semi
WebSocket ✅ Semi
gRPC ✅ Semi
BLoC / Riverpod ✅ Semi
Hive storage ✅ Semi
Dio HTTP ✅ Semi

Note: Default minLevel is WARN. Most automatic events are logged at DEBUG level and won't appear unless you set logger.minLevel = LogLevel.debug. Errors, crashes, timeouts, and stuck operations are always logged (WARN/ERROR/FATAL).

Log Format #

[TIME] [LEVEL] [SESSION] [CID] [COMPONENT] [EVENT] | MESSAGE | {METADATA}

Problem Markers #

  • ⚠️PROBLEM - Error with context
  • 🔴CRASH - Fatal crash
  • ⏰TIMEOUT - Operation timeout
  • ❌STUCK - Operation stuck/hung

Deduplication #

Errors include:

  • fingerprint = hash of error type + location (same bug)
  • trailHash = hash of user actions before error (same flow)

Optional Integrations #

// BLoC - create observer extending BlocObserver
class LoggingBlocObserver extends BlocObserver {
  @override void onCreate(BlocBase b) { super.onCreate(b); blocLogging.onCreate(b); }
  @override void onEvent(Bloc b, Object? e) { super.onEvent(b, e); blocLogging.onEvent(b, e); }
  @override void onChange(BlocBase b, Change c) { super.onChange(b, c); blocLogging.onChange(b, c); }
  @override void onTransition(Bloc b, Transition t) { super.onTransition(b, t); blocLogging.onTransition(b, t); }
  @override void onError(BlocBase b, Object e, StackTrace s) { super.onError(b, e, s); blocLogging.onError(b, e, s); }
  @override void onClose(BlocBase b) { super.onClose(b); blocLogging.onClose(b); }
}
Bloc.observer = LoggingBlocObserver();

// Riverpod - create observer extending ProviderObserver
class LoggingProviderObserver extends ProviderObserver {
  @override void didAddProvider(...) => riverpodLogging.didAddProvider(...);
  // ... other overrides calling riverpodLogging methods
}
// Pure Dart uses ProviderContainer (ProviderScope is Flutter-only)
final container = ProviderContainer(observers: [LoggingProviderObserver()]);

// Appwrite Realtime (monitor function executions from a long-running Dart app)
appwriteLogger.subscribe(realtime.subscribe(['executions']));

// WebSocket
final channel = LoggingWebSocketChannel.connect(Uri.parse('wss://example.com/ws'));

// Drift SQL (add .interceptWith to your database setup - logs ALL queries automatically)
NativeDatabase.createInBackground(file).interceptWith(loggingQueryInterceptor)

// gRPC (uses HTTP/2, not captured by HttpOverrides)
final result = await grpcLogger.call('UserService.GetUser', () => stub.getUser(request));

// Hive (works in pure Dart server apps)
final box = await Hive.openBox('myBox');
final loggingBox = LoggingHiveBox(box, name: 'myBox');
await loggingBox.put('key', 'value');

Defensive Coding Utilities #

9 Exception Types #

throw NetworkException('msg', statusCode: 500, url: url);
throw ValidationException('msg', field: 'email', invalidValue: v);
throw NotFoundException('msg', resourceType: 'User', resourceId: id);
throw StateException('msg', expectedState: 'ready', actualState: 'loading');
throw AppTimeoutException('op', Duration(seconds: 10));
throw PermissionException('msg', permission: 'camera');
throw AuthenticationException('msg');
throw StorageException('msg', path: '/file');
throw ParseException('msg', input: json, expectedFormat: 'JSON');

9 Validation Utilities #

Validate.notNull(v, 'name');
Validate.notEmpty(s, 'name');
Validate.listNotEmpty(l, 'name');
Validate.positive(n, 'name');
Validate.nonNegative(n, 'name');
Validate.inRange(n, 'name', 0, 100);
Validate.percentage(n, 'name');
Validate.email(s, 'name');
Validate.isTrue(cond, 'msg', field: 'name');

Loading Monitor #

// Detects stuck operations (default 2min threshold)
final result = await loadingMonitor.track('fetchData', () => api.getData());

// Hard timeout
final result = await withTimeout('op', () => api.call(), timeout: Duration(seconds: 30));

Documentation #

  • doc_ai_guide.md - Concise code-only reference for AI assistants
  • dart_auto_logger_developer_documentation.md - Full developer documentation with examples
  • doc3_human_log_parsing_guide.md - How to read and interpret logs

For Flutter Apps #

Use the auto_logger package instead, which includes all features from this package plus Flutter-specific logging (navigation, lifecycle, pointer events, keyboard, frame drops, memory leaks, etc.).

License #

MIT

0
likes
160
points
61
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Automatic debug logging for Dart (Appwrite functions). Pure Dart with no Flutter dependencies.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

drift, meta, stack_trace, talker, uuid, web_socket_channel

More

Packages that depend on dart_auto_logger