mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-26 14:50:17 +00:00
feat(logger): add extensible logging API, usage examples, and bilingual documentation
- Introduce CherryPickLogger interface, PrintLogger and SilentLogger implementations - Add setGlobalLogger() to CherryPick API for custom DI logging - Log key events (scope, module, error) via logger throughout DI lifecycle - Comprehensive comments and code documentation in both English and Russian - Document usage of logging system in quick_start and full_tutorial documentation (EN/RU) - Provide usage examples in docs and code comments - No logging inside GlobalCycleDetectionMixin (design choice: exceptions handled at Scope, not detector/mixin level) and detailed architectural reasoning - Update helper.dart, logger.dart: comments, examples, API doc improvements BREAKING CHANGE: Projects can now inject any logger via CherryPick.setGlobalLogger; default log behavior clarified and docstrings/usage examples enhanced
This commit is contained in:
37
cherrypick/example/cherrypick_logger_demo.dart
Normal file
37
cherrypick/example/cherrypick_logger_demo.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
|
||||
/// Example of a simple service class.
|
||||
class UserRepository {
|
||||
String getUserName() => 'Sergey DI';
|
||||
}
|
||||
|
||||
/// DI module for registering dependencies.
|
||||
class AppModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<UserRepository>().toInstance(UserRepository());
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Set a global logger for the DI system
|
||||
CherryPick.setGlobalLogger(PrintLogger());
|
||||
|
||||
// Open the root scope
|
||||
final rootScope = CherryPick.openRootScope();
|
||||
|
||||
// Register the DI module
|
||||
rootScope.installModules([AppModule()]);
|
||||
|
||||
// Resolve a dependency (service)
|
||||
final repo = rootScope.resolve<UserRepository>();
|
||||
print('User: ${repo.getUserName()}');
|
||||
|
||||
// Work with a sub-scope (create/close)
|
||||
final subScope = rootScope.openSubScope('feature.profile');
|
||||
subScope.closeSubScope('feature.profile');
|
||||
|
||||
// Demonstrate disabling and re-enabling logging
|
||||
CherryPick.setGlobalLogger(const SilentLogger());
|
||||
rootScope.resolve<UserRepository>(); // now without logs
|
||||
}
|
||||
Reference in New Issue
Block a user