Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions hive/lib/src/util/logger.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import 'dart:async';

import 'package:hive_ce/src/isolate/isolate_debug_name/isolate_debug_name.dart';
import 'package:hive_ce/src/util/debug_utils.dart';

// Dispatch through the current zone so that callers (most importantly tests)
// can intercept log output via Zone print specifications. The top-level
// `print` function relies on the global `printToZone` mutable field, which is
// only set as a side-effect of `_rootFork`. When `printToZone` is null in the
// current isolate, `print` writes directly to stdout, bypassing any zone
// `print` handler installed by `runZoned` and causing race-condition flakes
// in tests that use `captureOutput`.
void _zonePrint(Object? message) => Zone.current.print('$message');

/// Configures the logging behavior of Hive
abstract class Logger {
/// The overall logging level
Expand All @@ -35,35 +24,35 @@ abstract class Logger {
/// Log a verbose message
static void v(Object? message) {
if (level.index > LoggerLevel.verbose.index) return;
_zonePrint(message);
print(message);
}

/// Log a debug message
static void d(Object? message) {
if (level.index > LoggerLevel.debug.index) return;
_zonePrint(message);
print(message);
}

/// Log an informational message
static void i(Object? message) {
if (level.index > LoggerLevel.info.index) return;
_zonePrint(message);
print(message);
}

/// Log a warning message
static void w(Object? message) {
if (level.index > LoggerLevel.warn.index) return;
_zonePrint(message);
print(message);
}

/// Log an error message
static void e(Object? message) {
if (level.index > LoggerLevel.error.index) return;
_zonePrint(message);
print(message);
}

/// Log a message for an event that should not be possible
static void wtf(Object? message) => _zonePrint(message);
static void wtf(Object? message) => print(message);
}

/// Logging levels for Hive
Expand Down
Loading