All Projects → infinum → floggy

infinum / floggy

Licence: other
Customizable logger for dart and flutter applications.

Programming Languages

dart
5743 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to floggy

manila-mixins
A bunch of really cool Sass Mixins
Stars: ✭ 15 (-75.41%)
Mutual labels:  mixins
orchparty
Write your own orchestration config with a Ruby DSL that allows you to have mixins, imports and variables.
Stars: ✭ 37 (-39.34%)
Mutual labels:  mixins
desafios-DIO
Desafios em C#, Java, JavaScript, Kotlin, Python e Ruby dos Bootcamps da Digital Innovation One
Stars: ✭ 140 (+129.51%)
Mutual labels:  dio
ekzo
💫 Functional Sass framework for rapid and painless development
Stars: ✭ 32 (-47.54%)
Mutual labels:  mixins
buttono
A flexible Sass mixin for creating BEM-style buttons.
Stars: ✭ 82 (+34.43%)
Mutual labels:  mixins
snake-js
Nostálgico jogo da 🐍 em JavaScript.
Stars: ✭ 24 (-60.66%)
Mutual labels:  dio
vexana
Vexana is network manager project with dio.
Stars: ✭ 90 (+47.54%)
Mutual labels:  dio
vue-global-var
Reactive global variable can be sharable between components
Stars: ✭ 21 (-65.57%)
Mutual labels:  mixins
flutter read
A flutter project, 一款Flutter实战项目,已空安全适配,封装各种UI组件,网络组件以及使用peovider进行状态管理。
Stars: ✭ 51 (-16.39%)
Mutual labels:  dio
family.styl
port of family.scss to stylus
Stars: ✭ 19 (-68.85%)
Mutual labels:  mixins
flutter-netease
深度还原网易严选webApp,Flutter项目,接口为真实数据。项目已完善
Stars: ✭ 231 (+278.69%)
Mutual labels:  dio
easyMarketFlutter
Flutter开发仿网易严选
Stars: ✭ 160 (+162.3%)
Mutual labels:  dio
Orion
Mixin loader for Paper
Stars: ✭ 46 (-24.59%)
Mutual labels:  mixins
curso-dio-intro-collections
Resolução dos exercícios propostos: CURSO INTRODUTÓRIO COLLECTIONS FRAMEWORK JAVA.
Stars: ✭ 422 (+591.8%)
Mutual labels:  dio
Movie-Flutter
Movie App Flutter using Flutter BLoC, DIO, Retrofit, Sqflite
Stars: ✭ 36 (-40.98%)
Mutual labels:  dio
loopback-row-count-mixin
A loopback mixin to get total count of a model
Stars: ✭ 13 (-78.69%)
Mutual labels:  mixins
hagrid
📏 Hagrid is a mixin library for responsive websites and web applications.
Stars: ✭ 30 (-50.82%)
Mutual labels:  mixins
vue-reactive-provide
Plugin/Mixin wrapping Vue's static 'provide/inject' feature allowing to easily pass reactive data to children
Stars: ✭ 113 (+85.25%)
Mutual labels:  mixins
website
Prometheus monitoring mixins
Stars: ✭ 91 (+49.18%)
Mutual labels:  mixins
Mixin
React.js like Mixin. More powerful Protocol-Oriented Programming.
Stars: ✭ 45 (-26.23%)
Mutual labels:  mixins

Loggy

Loggy icon

Highly customizable logger for dart that uses mixins to show all the needed info.

Setup

Add logger package to your project:

dependencies:
    loggy: ^2.0.1+1

Usage

Now once you added loggy to your project you can start using it. First, you need to initialize it:

import 'package:loggy/loggy.dart';

main() {
  Loggy.initLoggy();
}

In case you just want to log something without adding mixin you can use GlobalLoggy that is accessible everywhere, and it will follow the rules set in initLoggy method

import 'package:loggy/loggy.dart';

class DoSomeWork {
 DoSomeWork() {
   logDebug('This is debug message');
   logInfo('This is info message');
   logWarning('This is warning message');
   logError('This is error message');
 }
}

While global loggy is easier to use, it cannot be easily filtered, and it cannot fetch the calling class.

By using mixins to access our logger, you can get more info from loggy, now I will show you how to use default types (UiLoggy, NetworkLoggy). Later in the customizing loggy part, I will show you how you can easily add more types depending on the specific use case.

import 'package:loggy/loggy.dart';

class DoSomeWork with UiLoggy {
 DoSomeWork() {
   loggy.debug('This is debug message');
   loggy.info('This is info message');
   loggy.warning('This is warning message');
   loggy.error('This is error message');
 }
}

As you can see with the magic of mixins you already know the class name from where the log has been called as well as which logger made the call. Now you can use loggy through the app.

[D] UI Loggy - DoSomeWork: This is debug message
[I] UI Loggy - DoSomeWork: This is info message
[W] UI Loggy - DoSomeWork: This is warning message
[E] UI Loggy - DoSomeWork: This is error message

Loggy can take anything as it's log message, even closures (they are evaluated only if the log has been shown)

loggy.info(() {
  /// You can do what you want here!
  const _s = 0 / 0;
  return List.generate(10, (_) => _s)
          .fold<String>('', (previousValue, element) => previousValue += element.toString()) +
      ' Batman';
});

Customization

Printer

Printer or how our log is displayed can be customized a lot, by default loggy will use DefaultPrinter, you can replace this by specifying different logPrinter on initialization, you can use PrettyPrinter that is already included in loggy. You can also easily make your printer by extending the LoggyPrinter class.

You can customize logger on init with the following:

import 'package:loggy/loggy.dart';

void main() {
 // Call this as soon as possible (Above runApp)
 Loggy.initLoggy(
  logPrinter: const PrettyPrinter(),
 );
}

Loggy with PrettyPrinter:

🐛 12:22:49.712326 DEBUG    UI Loggy - DoSomeWork - This is debug message
👻 12:22:49.712369 INFO     UI Loggy - DoSomeWork - This is info message
⚠️ 12:22:49.712403 WARNING  UI Loggy - DoSomeWork - This is warning message
‼️ 12:22:49.712458 ERROR    UI Loggy - DoSomeWork - This is error message

One useful thing is specifying different printer for release that logs to Crashlytics/Sentry instead of console.

You could create your own CrashlyticsPrinter by extending Printer and use it like:

  Loggy.initLoggy(
    logPrinter: (kReleaseMode) ? CrashlyticsPrinter() : PrettyPrinter(),
    ...
  );

Log options

By providing LogOptions you need to specify LogLevel that will make sure only levels above what is specified will be shown.

Here you can also control some logging options by changing the stackTraceLevel, by specifying level will extract stack trace before the log has been invoked, for all LogLevel severities above the specified one.

Setting stackTraceLevel to LogLevel.error:

🐛 12:26:48.432602 DEBUG    UI Loggy - DoSomeWork - This is debug message
👻 12:26:48.432642 INFO     UI Loggy - DoSomeWork - This is info message
⚠️ 12:26:48.432676 WARNING  UI Loggy - DoSomeWork - This is warning message
‼️ 12:26:48.432715 ERROR    UI Loggy - DoSomeWork - This is error message
#0      Loggy.log (package:loggy/src/loggy.dart:195:33)
#1      Loggy.error (package:loggy/src/loggy.dart:233:73)
#2      new DoSomeWork (.../loggy/example/loggy_example.dart:29:11)
#3      main (.../loggy/example/loggy_example.dart:21:3)
#4      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Custom loggers

You can have as many custom loggers as you want, by default you are provided with 2 types: NetworkLoggy and UiLoggy

To make a custom logger you just need to make a new mixin that implements LoggyType and returns new logger with mixin type:

import 'package:loggy/loggy.dart';

mixin CustomLoggy implements LoggyType {
  @override
  Loggy<CustomLoggy> get loggy => Loggy<CustomLoggy>('Custom Loggy - $runtimeType');
}

Then to use it just add with CustomLoggy to the class where you want to use it.

Custom log levels

You can add new LogLevel to log like this:

// LogLevel is just a class with `name` and `priority`. Priority can go from 1 - 99 inclusive.
const LogLevel socketLevel = LogLevel('socket', 32);

When adding a new level it's also recommended extending the Loggy class as well to add quick function for that level.

extension SocketLoggy on Loggy {
  void socket(dynamic message, [Object error, StackTrace stackTrace]) => log(socketLevel, message, error, stackTrace);
}

You can now use new log level in the app:

loggy.socket('This is log with socket log level');

Filtering

Now you have a lot of different types and levels how to find what you need? You may need to filter some of them. We have WhitelistFilter, BlacklistFilter and CustomLevelFilter.

Filtering is a way to limit log output without actually changing or removing existing loggers. Whitelisting some logger types will make sure only logs from that specific type are shown. Blacklisting will do the exact opposite of that. This is useful if your loggers log ton of data and pollute the console so it's hard to see valuable information.

  Loggy.initLoggy(
    ... // other stuff
    filters: [
      BlacklistFilter([SocketLoggy]) // Don't log logs from SocketLoggy
    ],
  );

More loggers?

Do you need more loggers? No problem!

Any class using Loggy mixin can make new child loggers with newLoggy(name) or detachedLoggy(name).

Child logger

newLoggy(name) will create a new child logger that will be connected to the parent logger and share the same options. Child loggy will have parent name included as the prefix on a child's name, divided by ..

Detached logger

detachedLoggy(name) is a logger that has nothing to do with the parent loggy and all options will be ignored. If you want to see those logs you need to attach a printer to it.

final _logger = detachedLoggy('Detached logger', logPrinter: DefaultPrinter());
_logger.level = const LogOptions(LogLevel.all);
// Add printer

Loggy 💙 Flutter

Extensions that you can use in Flutter to make our logs look nicer. In order to fully use Loggy features in flutter make sure you are importing flutter_loggy pub package. In it you can find printer for flutter console PrettyDeveloperPrinter and widget that can show you all the logs: LoggyStreamWidget

Pretty developer printer

Loggy.initLoggy(
  logPrinter: PrettyDeveloperPrinter(),
);

This printer uses dart:developer and can write error messages in red, and it gives us more flexibility. This way you can modify this log a bit more and remove log prefixes (ex. [ ] I/flutter (21157))

To see logs in-app you can use StreamPrinter and pass any other printer to it. Now you can use LoggyStreamWidget to show logs in a list.

Loggy 💙 Dio as well!

Extension for loggy. Includes the interceptor and pretty printer to use with Dio. In order to use Dio with Loggy you will have to import flutter_loggy_dio package, that will include an interceptor and new loggy type for Dio calls.

Usage

For Dio you included special DioLoggy that can be filtered, and LoggyDioInterceptor that will connect to Dio and print out requests and responses.

Dio dio = Dio();
dio.interceptors.add(LoggyDioInterceptor());

That will use Loggy options and levels, you can change the default LogLevel for request, response, and error.

Setup

In IntelliJ/Studio you can collapse the request/response body: Gif showing collapsible body

Set up this is by going to Preferences -> Editor -> General -> Console and under Fold console lines that contain add these 3 rules: , and . Settings

Features and bugs

Please file feature requests and bugs at the issue tracker.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].