Coder Social home page Coder Social logo

plugfox / l Goto Github PK

View Code? Open in Web Editor NEW
36.0 2.0 3.0 2.79 MB

Cross-platform html/io [L]ogger with simple API.

Home Page: https://pub.dev/packages/l

License: MIT License

Dart 98.19% Makefile 1.81%
log logging logger logs logging-library l cross-platform html io wtfpl flutter dart dartlang dart-library dart-package package pub

l's Introduction

[L]ogger

Pub Actions Status Coverage License: MIT Linter GitHub stars

About

Cross-platform html/io logger with simple API. No need to create a logger object. Just import and use. Simple and w/o boilerplate. Work with native console.

Core API

Example of usage

Example of using the library to display a message in the console.

Key features

Method Description
[s] A shout is always displayed
[v1], [v] Regular message with verbose level 1
[e] Error message with verbose level 1
[v2], [vv] Regular message with verbose level 2
[w] Warning message with verbose level 2
[v3], [vvv] Regular message with verbose level 3
[i], [<] Inform message with verbose level 3
[v4], [vvvv] Regular message with verbose level 4
[d], [<<] Debug message with verbose level 4
[v5], [vvvvv] Regular message with verbose level 5
[v6], [vvvvvv] Regular message with verbose level 6
l.s('shout me');
l.e('error msg');
l.w('warning msg');
l.i('info msg');
l < 'alt info msg';
l.d('debug msg');
l << 'alt debug msg';
l.v('verbose lvl #1');
l.vv('verbose lvl #2');
l.vvv('verbose lvl #3');
l.v4('verbose lvl #4');
l.v5('verbose lvl #5');
l.v6('verbose lvl #6');

Integration capabilities

Method Description
[listen] Broadcast stream receiving logs.
// Broadcast stream instantly receiving logs.
l.forEach((log) => print('* ${log.level} : ${log.message}'));

Print handling and customizing

Logger supports fine-tuning with the second argument LogOptions in a capture method. Also, you can handle print and output with l on some function or in a whole app with this simple syntax:

import 'package:l/l.dart';

void main() => l.capture(
      someFunction,
      const LogOptions(
        handlePrint: true,
        printColors: true,
        outputInRelease: false,
        messageFormatting: _messageFormatting,
      ),
    );

Future<void> someFunction() async {
  print('Hello');
  await Future<void>.delayed(const Duration(milliseconds: 150));
  l.d('world');
  await Future<void>.delayed(const Duration(milliseconds: 150));
  l.e('!!!');
}

Object _messageFormatting(Object message, LogLevel logLevel, DateTime now) =>
    '${now.hour}:${now.minute.toString().padLeft(2, '0')} $message';

Handling errors

Flutter

final sourceFlutterError = FlutterError.onError;
FlutterError.onError = (details) {
  l.w(details.exceptionAsString(), details.stack);
  sourceFlutterError?.call(details);
};

Crashlytics

l.where((msg) => msg.level.maybeWhen(
      error: () => true,
      warning: () => true,
      orElse: () => false,
    ))
  .map<String>((msg) => msg.message.toString())
  .listen(FirebaseCrashlytics.instance.log);

Zoned Errors

runZonedGuarded(someFunction, l.e);

Handling uncaught errors

Isolate.current
       ..setErrorsFatal(false)
       ..addErrorListener(
         RawReceivePort(
           (List<dynamic> pair) => // ignore: avoid_types_on_closure_parameters
               l.e(pair.first as Object),
         ).sendPort,
       );

Limitations

  • When there is no direct access to the terminal, it works through print.
  • !!! PLEASE, DO NOT LOG SENSITIVE INFORMATION !!!

Changelog

Refer to the Changelog to get all release notes.

Maintainers

Plague Fox

Funding

If you want to support the development of our library, there are several ways you can do it:

We appreciate any form of support, whether it's a financial donation or just a star on GitHub. It helps us to continue developing and improving our library. Thank you for your support!

License

MIT

l's People

Contributors

plugfox avatar purplenoodlesoop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

l's Issues

Override log icons

Override like this:

๐Ÿ› 12:22:49.712326 DEBUG  - DoSomeWork - This is debug message
๐Ÿ‘ป 12:22:49.712369 INFO - DoSomeWork - This is info message
โš ๏ธ 12:22:49.712403 WARNING  - DoSomeWork - This is warning message

Any exception or error resulting in Stack Overflow.

Hello!

There seems to be a specific combination of options and arguments that results in an uncontrollable Stack Overflow exception. I've managed to reproduce this behavior using the following code:

void main() => l.capture(
      () => runZonedGuarded(
        () => throw Exception(),
        (e, s) => print(e),
      ),
      LogOptions(
        handlePrint: false,
      ),
    );

Using the logger itself as the runZonedGuarded's onError argument or leaving the LogOptions' handlePrint as its default does not trigger the issue. The exception's StackTrace is not very informative, as it points to only two segments repeatedly, and those segments are _CustomZone.print and InnerZonedMixin.capture:

#0      _CustomZone._parentDelegate (dart:async/zone.dart:1150:3)
#1      _CustomZone.print (dart:async/zone.dart:1400:55)
#2      InnerZonedMixin.capture.<anonymous closure> (package:l/src/inner_zoned_mixin.dart:43:20)
#3      _CustomZone.print (dart:async/zone.dart:1402:19)
#4      InnerZonedMixin.capture.<anonymous closure> (package:l/src/inner_zoned_mixin.dart:43:20)
#5      _CustomZone.print (dart:async/zone.dart:1402:19)
#6      InnerZonedMixin.capture.<anonymous closure> (package:l/src/inner_zoned_mixin.dart:43:20)
...

Maximum length of the log message

Field for indicating the maximum length of the log message.
If exceeded, transfer to the next line.
Also format multi-line comments.

1589308341934 [I] Single line
1589308342053 [I] Multi
                | Line
                | Message
1589308342053 [I] Single line

Print Stack Trace to log when it had been passed

Could be nice to print Stack Trace to log when it had been passed to the l.e() or l.w()
For example if we passing Error and Stack Trace to the Sentry - we expect to see clear Error message without Stack Trace and Stack Trace as additional record.
And for the debug it could be nice to always see Stack Trace in the console if it is possible.
Maybe it could be option to print Stack Trace.

messageFormatting - add StackTrace parameter

Could be nice to add stackTrace parameter to easily print stackTrace to log using predefined formating.

final logOptions = LogOptions(
      messageFormatting: formatLoggerMessage,
    );
l.capture(fn, logOptions);

String formatLoggerMessage(
      Object message,
  ->  StackTrace stackTrace,
      logging.LogLevel level,
      DateTime time,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.