• Stars
    star
    115
  • Rank 299,891 (Top 7 %)
  • Language
    Dart
  • Created almost 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Customizable logger for dart and flutter applications.

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.2

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.

More Repositories

1

android_dbinspector

Android library for viewing, editing and sharing in app databases.
Kotlin
945
star
2

rails-handbook

Describing the development process used by the Infinum Rails Team.
Slim
763
star
3

FBAnnotationClustering

iOS library for clustering map notifications in an easy and performant way
Objective-C
713
star
4

Android-Goldfinger

Android library to simplify Biometric authentication implementation.
Java
652
star
5

ios-viper-xcode-templates

Used for generating template files for the VIPER architecture, which solves the common Massive View Controller issues in iOS apps.
HTML
576
star
6

phrasing

Edit phrases inline for your Ruby on Rails applications!
Ruby
544
star
7

eightshift-boilerplate

This repository contains all the tools you need to start building a modern WordPress theme, using all the latest front end development tools.
PHP
511
star
8

Android-GoldenEye

A wrapper for Camera1 and Camera2 API which exposes simple to use interface.
Kotlin
375
star
9

cookies_eu

Gem to add cookie consent to Rails application
Haml
266
star
10

dox

Automated API documentation from Rspec
Ruby
234
star
11

MjolnirRecyclerView

[DEPRECATED] This library is no longer maintained and it will not receive any more updates.
Java
220
star
12

ios-nuts-and-bolts

iOS bits and pieces that you can include in your project to make your life a bit easier.
Swift
195
star
13

Japx

Lightweight parser for the complex JSON:API (http://jsonapi.org/) structure.
Swift
150
star
14

flutter-charts

Customizable charts library for flutter.
Dart
139
star
15

datx

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
TypeScript
137
star
16

learnQuery

Learn JavaScript fundamentals by building your own jQuery equivalent library
JavaScript
137
star
17

flutter-dasher

Dart
116
star
18

android-complexify

An Android library which makes checking the quality of user's password a breeze.
Java
113
star
19

Android-Prince-of-Versions

Android library for handling application updates.
Java
104
star
20

android_connectionbuddy

Utility library for handling connectivity change events.
Java
94
star
21

eightshift-docs

A documentation website for Eightshift open source projects
JavaScript
79
star
22

eightshift-frontend-libs

Frontend library that exposes custom scripts and styles for modern WordPress projects
JavaScript
69
star
23

Retromock

Java library for mocking responses in a Retrofit service.
Kotlin
67
star
24

eightshift-libs

Library that is meant to be used inside Eightshift Boilerplate and Eightshift Boilerplate Plugin libs via composer in order to be able to easily set up a modern development process.
PHP
61
star
25

frontend-handbook

Our handbook based on 10 years of experience in Frontend/JS development
Slim
57
star
26

Locker

Securely lock your secrets under the watch of TouchID or FaceID keeper ๐Ÿ”’
Swift
50
star
27

emotion-normalize

normalize.css but for emotion.js
JavaScript
50
star
28

mobx-jsonapi-store

JSON API Store for MobX
TypeScript
48
star
29

Dagger-2-Example

Dagger 2 example project
Java
44
star
30

ios-prince-of-versions

Library used for easier versioning of your applications, allowing you to prompt your users to update the app to the newest version
Swift
43
star
31

enumerations

Better Rails Enumerations
Ruby
37
star
32

kotlin-jsonapix

JsonApiX is an Android, annotation processor library that was made to transform regular Kotlin classes into their JSON API representations, with the ability to serialize or deserialize them to or from strings.
Kotlin
36
star
33

eightshift-boilerplate-plugin

This repository contains all the tools you need to start building a modern WordPress plugin.
PHP
36
star
34

mobx-collection-store

Data collection store for MobX
TypeScript
35
star
35

android-sentinel

Sentinel is a simple one screen UI which provides a standardised entry point for tools used in development and QA alongside device, application and permissions data.
Kotlin
35
star
36

decoupled-json-content

JavaScript
30
star
37

wordpress-handbook

Official WordPress handbook at Infinum
Slim
30
star
38

webpack-asset-pipeline

๐Ÿš€ A missing link for the asset pipeline alternative with Webpack.
JavaScript
30
star
39

ios-loggie

Simplify debugging by showing network requests of your app as they happen.
Swift
30
star
40

flutter-plugins-locker

Flutter plugin that secures your secrets in keychain using biometric authentication (Fingerprint, Touch ID, Face ID...).
Dart
29
star
41

default_rails_template

Default template for generating new Rails applications.
Ruby
27
star
42

eightshift-forms

WordPress plugin project for Gutenberg forms
PHP
27
star
43

media-blender

Easy and predictable SASS/SCSS media queries
CSS
26
star
44

android-collar

Gradle plugin which collects all analytics screen names, events and user properties for Android projects.
Kotlin
26
star
45

secrets_cli

CLI for storing and reading your secrets via vault
Ruby
25
star
46

flutter-plugins-japx

JSON API parser for Flutter
Dart
24
star
47

flutter-bits

Flutter
Dart
22
star
48

react-mobx-translatable

Make React components translatable using MobX
JavaScript
21
star
49

dungeons-and-dragons

๐ŸŽฒ Dungeons & Dragons Character builder and keeper (work in progress)
TypeScript
19
star
50

android-crash-handler

Utility library which handles crash handler configuration
Java
19
star
51

qa-handbook

Describing the processes used by the Infinum QA Team
Slim
18
star
52

iOS-Bugsnatch

Swift
18
star
53

eightshift-coding-standards

Eightshift coding standards for WordPress
PHP
16
star
54

jsonapi-query_builder

Ruby
14
star
55

thrifty-retrofit-converter

Retrofit converter which uses Thrifty for Apache Thrift-compatible serialization
Java
13
star
56

json-wp-post-parser

JSON Post Parser plugin parses your content and saves it as JSON available in REST posts and pages endpoints.
PHP
13
star
57

swift-style-guide

12
star
58

generator-infinitely-static

๐Ÿ’ซ Static page generator with routes support thats infinitely awesome
JavaScript
11
star
59

react-responsive-ssr

TypeScript
11
star
60

JS-React-Example

Infinum's way of doing React
TypeScript
10
star
61

ngx-hal

Angular datastore library with HAL support
TypeScript
10
star
62

fiscalizer

A gem for fiscalizing invoices in Croatia using Ruby.
Ruby
9
star
63

ember-form-object

Form object pattern in ember apps
JavaScript
9
star
64

js-talks

โœจ Interesting talks and mini lectures about new and cool stuff that's going on in the world of JS development, organized by the Infinum JS team
9
star
65

android-handbook

Slim
8
star
66

js-linters

Infinum's JS team linter rules
TypeScript
7
star
67

auth-worker

OAuth2 Service Worker handler
TypeScript
7
star
68

array_validator

Array Validations for ActiveModel
Ruby
7
star
69

eightshift-storybook

Storybook package for Eightshift-Boilerplate
7
star
70

icomcom-react

๐Ÿ’ฌ A React component for handling communication with content in <iframe />
JavaScript
7
star
71

dox-demo

Demo app for dox gem:
HTML
6
star
72

android-localian

Android library that manages your application locale and language across multiple Android API levels.
Kotlin
6
star
73

ios-handbook

Slim
6
star
74

flutter-prince-of-versions

Library used for easier versioning of your applications, allowing you to prompt your users to update the app to the newest version
Dart
6
star
75

learn-react

๐Ÿ‘‹ โš›๏ธ Learn React by implementing your own!
TypeScript
5
star
76

I18n-js

Javascript library for string internationalization.
CoffeeScript
5
star
77

ios-collar

In-app analytics debugging tool
Swift
5
star
78

ngx-form-object

Reactive forms manager
TypeScript
5
star
79

ios-sentinel

Developerโ€™s toolbox for debugging applications
Swift
4
star
80

mobx-keys-store

Keys store for MobX
TypeScript
4
star
81

mysterious-sampler

Swift
4
star
82

rails-infinum-jsonapi_example_app_old

Ruby
4
star
83

phrasing_plus

Phrasing extension for editing images inline
Ruby
4
star
84

eightshift-web-components

Web components library that exposes custom scripts and styles for modern WordPress projects
Svelte
4
star
85

Install-Flutter-Version-Manager-Bitrise

Shell
4
star
86

infinum_setup

Setup script
Ruby
4
star
87

loglevel-filesave

Loglevel plugin for saving logs to the file
JavaScript
4
star
88

eightshift-blocks

Project dedicated to use inside WP Boilerplate and WP Boilerplate Plugin projects via composer to be able to easily setup modern development process for Gutenberg blocks..
PHP
3
star
89

data_sync

Rails plugin for database and file synchronization
Ruby
3
star
90

next-passenger

next.js with passenger proof of concept
Dockerfile
3
star
91

SocketMan

Android WebSocket client app
Java
3
star
92

react-asset-collector

Collect assets from react components so you can do HTTP2 push
JavaScript
3
star
93

rails_log_book

Ruby
3
star
94

mina-secrets

Mina plugin for secrets_cli gem
Ruby
2
star
95

docusaurus-theme

Infinum Docusaurus teme
JavaScript
2
star
96

ngx-nuts-and-bolts

A collection of commonly used pieces of Angular-related code that we use everyday at Infinum.
TypeScript
2
star
97

money_with_date

Extension for the money gem which adds dates to Money objects.
Ruby
2
star
98

blog-android-permissions

Java
2
star
99

JS-RxWorkshop

TypeScript
2
star
100

analytics-handbook

2
star