Skip to content

Commit

Permalink
Core logger refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Nov 2, 2021
1 parent 08a4ddf commit 49149cb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 33 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ build/
.flutter-plugins

coverage
example/ios/Flutter/flutter_export_environment.sh
example/ios/Flutter/flutter_export_environment.sh

# VS Code
.vscode
.history
1 change: 0 additions & 1 deletion bin/flutter_i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'actions/ValidateAction.dart';
void main(final List<String> args) async {
validateLength(args);
final AbstractAction actionInterface = retrieveAction(args[0]);
MessagePrinter.setMustPrintMessage(true);
actionInterface.executeAction(args.sublist(1));
}

Expand Down
4 changes: 4 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:logging/logging.dart';

import 'basic_example.dart' as basicExample;
import 'local_example.dart' as localeExample;
Expand All @@ -15,6 +16,9 @@ Future main() async {
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Logger.root.onRecord.listen((record) {
print(record);
});
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
Expand Down
33 changes: 20 additions & 13 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "22.0.0"
version: "30.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.1"
version: "2.7.0"
archive:
dependency: transitive
description:
Expand All @@ -35,7 +35,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
cli_util:
dependency: transitive
description:
Expand Down Expand Up @@ -126,7 +126,7 @@ packages:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
version: "6.1.2"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -159,6 +159,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
frontend_server_client:
dependency: transitive
description:
name: frontend_server_client
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -224,7 +231,7 @@ packages:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.0.2"
matcher:
dependency: transitive
description:
Expand All @@ -238,7 +245,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -343,7 +350,7 @@ packages:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.1"
version: "4.2.3"
pub_semver:
dependency: transitive
description:
Expand Down Expand Up @@ -453,21 +460,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.8"
version: "1.17.10"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.2"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.19"
version: "0.4.0"
toml:
dependency: transitive
description:
Expand Down Expand Up @@ -495,7 +502,7 @@ packages:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "6.2.0"
version: "7.1.1"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -560,5 +567,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.13.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=2.0.0"
1 change: 0 additions & 1 deletion lib/flutter_i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class FlutterI18n {
this.missingTranslationHandler =
missingTranslationHandler ?? (key, locale) {};
this.keySeparator = keySeparator;
MessagePrinter.setMustPrintMessage(!Foundation.kReleaseMode);
}

/// Used to load the locale translation file
Expand Down
19 changes: 6 additions & 13 deletions lib/utils/message_printer.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import 'package:logging/logging.dart';

/// Used to print console messages with the flutter_i18n prefix
class MessagePrinter {
static bool _mustPrintMessage = false;

static setMustPrintMessage(bool mustPrintMessage) =>
_mustPrintMessage = mustPrintMessage;
static final logger = Logger("flutter_i18n");

static debug(final String message) {
_printMessage("DEBUG", message);
logger.fine(message);
}

static info(final String message) {
_printMessage("INFO", message);
logger.info(message);
}

static error(final String message) {
_printMessage("ERROR", message);
}

static _printMessage(final String prefix, final String message) {
if (_mustPrintMessage) {
print("[flutter_i18n $prefix]: $message");
}
logger.shout(message);
}
}
15 changes: 11 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -84,6 +84,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
logging:
dependency: "direct main"
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
matcher:
dependency: transitive
description:
Expand All @@ -97,7 +104,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: "direct main"
description:
Expand Down Expand Up @@ -172,7 +179,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.2"
toml:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
xml2json: ^5.3.1
path: ^1.8.0
toml: ^0.11.0
logging: ^1.0.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 49149cb

Please sign in to comment.