In order to centralize Flutter logs using log.jod.li , one needs to:
- Create an account for free on https://en.log.jod.li
- Add the following to pubspec.yaml under dependencies:
http: ^0.12.0+2
- Click on “Packages get” of run this command at the project root folder:
flutter packages get
- Import the following:
import 'package:http/http.dart' as http;
import 'dart:io'; - Add this function:
Future jilog (String message,{bool encoded=false})async {
try {
String m="";
String remaining="";
if(!encoded){
m=Uri.encodeFull(message);
}
else{
m=message;
}
if(m.length>1700){
remaining=m.substring(1700);
m=m.substring(0,1700);
}
final response = await http.get('https://en.log.jod.li/?api=a&u=myUserName&k=my16CharsLongKey&c=myGUID&a=myApp&m=${m}');
if(remaining.length>0){
jilog(remaining, encoded:true);
}
}
catch(e){
print("Error: Failed to send logs: ${e.toString()}");
}
}
- Replace in the function the following elements of the URL:
myUserName: user name received in the email at free user registration on log.jod.li .
my16CharsLongKey: 16 characters long key received in the email at free user registration on log.jod.li .
myGUID: arbitrary string that is meant for you to identify the user anonymously. You can also leave it as it is.
myApp: arbitrary string that is meant for you to identify the application sending the logs. You can also leave it as it is.
Note that this URL is prebuilt in the log.jod.li free registration email. - Call the function to add logs:
jilog("Yes, this got executed!");
- Check your logs from the log.jod.li page (link in the registration email or enter your user and key on the page).
The logs will flow on the page as they are sent by your Flutter code.