Skip to main content

dart_auto_logger 1.0.2 copy "dart_auto_logger: ^1.0.2" to clipboard
dart_auto_logger: ^1.0.2 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 #

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});
  });
}

What's Logged Automatically #

Category Supported
HTTP requests ✅
File operations ✅
Timers ✅
Errors/crashes ✅
Print statements ✅
Slow callbacks ✅

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 function logs in IDE
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));

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

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

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
0
points
75
downloads

Publisher

unverified uploader

Weekly Downloads

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

drift, meta, talker, uuid, web_socket_channel

More

Packages that depend on dart_auto_logger