logging_service 3.2.2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 67

pub Build Status codecov documentation

The service for advanced work with logging

Motivation:

You start using logging package. You are able to change log-level for the whole application only. Or you should set log level manually for every new Logger instance inside the code. It is not very convenient.
We wanted to change log-levels per module, and change log-levels per module and for the whole app in runtime. With this library you will be able to do it, even a little bit more - read below.

The fast start example:

final loggingService = new LoggingService()..start();

ConfigureLoggingForBrowser.setUpAll(
  loggingService,
  appVersionUid: 'app_uid', 
  sentryDsn: 'https://123456789abcdef123456789abcdef12@sentry.local/1'
);

loggingService.runProtected(() {
  //Your own app code
  var logger1 = new Logger('myModuleName1');
  logger1.info('Some info');
  
  var logger2 = new Logger('myModuleName2');
  logger2.severe('Some error! We should fix it!');
  logger2.shout('Some dev-message');
});

What do you get as a result (each feature can be disabled by configuration):

  1. You can manage log level per module:
    By code: LoggingService.setLogLevelPerLogger(String loggerName, log.Level level)
    In runtime by adding the hash parameter to your app-url: #logging={"myModuleName": "SEVERE"} myModuleName should be the name that you used when you created new Logger('myModuleName');

By default you will see in the browser console only Level.SEVERE and higher levels of messages. But if you want to change it you can manage the base level for the whole application:
By code: LoggingService.setLogLevelPerLogger(LoggingService.ROOT_LOG_LEVEL_KEY, log.Level level)
or to set it with the call of: loggingService.start(rootLogLevel: Level.INFO)
In runtime by adding the hash parameter to your app-url: #logging={"rootLogLevel": "INFO"}

  1. You SEVERE messages are being saved to the sentry server: If you put the appVersionUid and sentryDsn arguments to the ConfigureLoggingForBrowser.setUpAll() call.
    Or if you configured saver manually loggingService.addLoggingSavers([new LoggingSaverForSentry(...)]);
    You can change the level for what message is being sent to the savers by changing the savableLogLevel arg for the loggingService.start(savableLogLevel: Level.SEVERE) call.

  2. The default printer is printing messages and exceptions in accordance with your levels-settings. It prints exceptions in a way that allows the browser to use source-maps and show you source-code links if you had connected the source-map file.

  3. The exceptions inside the loggingService.runProtected() call will be captured and chained by default.
    It means that you will see the whole sequence of calls (and their stack-traces) that led to the error.
    Yes, I now that there are some fears that chaining is slow. But you will see it only if you use long nested sequences of call. Very long, like 100-1000 levels. If the size of you sequence is something like 4-10 as usual - the chaining of stack-traces is not your bottleneck, even not a problem. We checked it for us and use it in production.

  4. The system listens js-errors (through window.onError) and handles them.

  5. The system can collect even js-errors that had happened before the dart-code started:
    To do this you should put js-code-snippet from the lib/pre_start_js_collector_code.js to the very beginning of your scripts.

  6. If you want to collect errors from the dart-angular you should use something like this:

import 'package:angular2/di.dart';
import 'package:logging/logging.dart' as log;
import 'package:logging_service/logging_service.dart';
import 'package:stack_trace/stack_trace.dart';

class AppExceptionHandler implements ExceptionHandler {
  final LoggingService _loggingService;

  AppExceptionHandler(loggingService) : this._loggingService = loggingService;

  @override
  void call(dynamic error, [dynamic stackTrace, String reason]) {
        if (stackTrace is Iterable) {
          stackTrace = new Chain((stackTrace as Iterable).map((dynamic trace) => new Trace.parse(trace.toString())));
        } else {
          stackTrace = new Trace.parse(stackTrace.toString());
        }

        _loggingService.handleLogRecord(
          new log.LogRecord(
            log.Level.SEVERE,
            reason,
            'ngErrorLogger',
            error,
            stackTrace as StackTrace,
          ),
        );
  }
}

and then put the provider for ExceptionHandler to your bootstrap call:

bootstrap(AppComponent, [new Provider(ExceptionHandler, useValue: new AppExceptionHandler(loggingService))]);

Changelog

3.2.2

  • Dart 2 fixes

3.2.1

  • Fix README

3.2.0

  • Improve display errors experience

3.1.1

  • Fix a type error inside the window.onError callback #4

3.1.0

  • Add js to dart logging

3.0.3

  • Fix the "uses_dynamic_as_bottom" for the Dart-2.0

3.0.2

  • Just the version bumping

3.0.1

  • Check the ci integration

3.0.0

  • The first open-source version

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  logging_service: ^3.2.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:logging_service/logging_service.dart';
  
Version Uploaded Documentation Archive
3.2.2 Jul 2, 2018 Go to the documentation of logging_service 3.2.2 Download logging_service 3.2.2 archive
3.2.1 Apr 10, 2018 Go to the documentation of logging_service 3.2.1 Download logging_service 3.2.1 archive
3.1.1 Mar 19, 2018 Go to the documentation of logging_service 3.1.1 Download logging_service 3.1.1 archive
3.1.0 Feb 11, 2018 Go to the documentation of logging_service 3.1.0 Download logging_service 3.1.0 archive
3.0.3 Jan 2, 2018 Go to the documentation of logging_service 3.0.3 Download logging_service 3.0.3 archive
3.0.2 Oct 3, 2017 Go to the documentation of logging_service 3.0.2 Download logging_service 3.0.2 archive
3.0.1 Aug 21, 2017 Go to the documentation of logging_service 3.0.1 Download logging_service 3.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:logging_service/logging_service.dart.

Health suggestions

Format lib/configure_logging_for_browser.dart.

Run dartfmt to format lib/configure_logging_for_browser.dart.

Format lib/infinite_loop_protector.dart.

Run dartfmt to format lib/infinite_loop_protector.dart.

Format lib/logging_printer_for_browser.dart.

Run dartfmt to format lib/logging_printer_for_browser.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/logging_saver_for_sentry.dart (Run dartfmt to format lib/logging_saver_for_sentry.dart.)
  • lib/logging_service.dart (Run dartfmt to format lib/logging_service.dart.)
  • lib/logging_speed.dart (Run dartfmt to format lib/logging_speed.dart.)
  • lib/sentry_pre_save_for_browser.dart (Run dartfmt to format lib/sentry_pre_save_for_browser.dart.)
  • lib/src/configure_js_to_dart_logs_writer.dart (Run dartfmt to format lib/src/configure_js_to_dart_logs_writer.dart.)
  • lib/src/js_console_proxy.dart (Run dartfmt to format lib/src/js_console_proxy.dart.)

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use logging_service.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.1 <3.0.0
js ^0.6.0 0.6.1+1
logging ^0.11.0 0.11.3+2
sentry_client ^4.0.0 4.2.1
stack_trace ^1.8.0 1.9.3
Transitive dependencies
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
path 1.6.2
typed_data 1.1.6
uuid 1.0.3
Dev dependencies
build_runner >=0.9.1 <2.0.0
build_test >=0.10.2 <2.0.0
build_web_compilers >=0.4.0 <2.0.0
coverage >=0.7.9 <2.0.0
dart_dev >=1.7.2
mockito >=3.0.0-beta+1 <4.0.0
quiver >=0.21.4 <2.0.0
test >=0.12.15 <2.0.0