Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 75 additions & 20 deletions fimber/lib/src/fimber_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,59 @@ abstract class LogTree {

/// Gets levels of logging serviced by this [LogTree]
List<String> getLevels();
static final _logMatcher =
RegExp(r"([a-zA-Z\<\>\s\.]*)\s\(\w+:\/(.*\.dart):(\d*):(\d*)");

static final _lineInfoMatcher = RegExp(r"\(\w+:(.*\.dart):(\d*)[:(\d*)]");

/// "#4 main.<anonymous closure>.<anonymous closure> (file:///Users/magillus/Projects/opensource/flutter-fimber/fimber/test/fimber_test.dart:19:14)"
/// “#4 _MyAppState.build.<anonymous closure> (package:flutter_fimber_example/main.dart:83:26)
/// “#4 _MyAppState.build (package:flutter_fimber_example/main.dart:83)

/// Gets [LogLineInfo] with [stackIndex]
/// which provides data for tag and line of code
static LogLineInfo getLogLineInfo({int stackIndex = 4}) {
var stackTraceList = StackTrace.current.toString().split('\n');
if (stackTraceList.length > stackIndex) {
var stackinfo = stackTraceList[stackIndex];
var lineParts = _getLineChunks(stackinfo);
var tag = _defaultTag;
var lineinfo = '(package:flutter_fimber/error.dart:0:0)';
if (lineParts.length > 3 && lineParts[1] == 'new') {
// constructor logging
tag = "${lineParts[1]} ${lineParts[2]}";
lineinfo = lineParts[3];
} else if (lineParts.length > 2) {
lineinfo = lineParts[2];
tag = lineParts[1];
} else if (lineParts.length > 1) {
tag = lineParts[1];
}

final matches = _lineInfoMatcher.allMatches(lineinfo);
if (matches.isNotEmpty) {
final match = matches.first;
if (match.groupCount == 3) {
return LogLineInfo(
tag: tag,
logFilePath: match.group(1),
lineNumber: int.tryParse(match.group(2) ?? '-1') ?? -1,
characterIndex: int.tryParse(match.group(3) ?? '-1') ?? -1,
);
}
return LogLineInfo(
tag: tag,
logFilePath: match.group(1),
lineNumber: int.tryParse(match.group(2) ?? '-1') ?? -1,
);
}
}
return LogLineInfo(
tag: _defaultTag,
);
}

/*
static final _logMatcher =
RegExp(r"([a-zA-Z\<\>\s\.]*)\s\(\w+:(.*\.dart):(\d*):(\d*)");
/// Gets [LogLineInfo] with [stackIndex]
/// which provides data for tag and line of code
static LogLineInfo getLogLineInfo({int stackIndex = 4}) {
Expand All @@ -287,6 +337,9 @@ abstract class LogTree {
/// group 3 = line number
/// group 4 = column
/// "#4 main.<anonymous closure>.<anonymous closure> (file:///Users/magillus/Projects/opensource/flutter-fimber/fimber/test/fimber_test.dart:19:14)"
/// “#4 _MyAppState.build.<anonymous closure> (package:flutter_fimber_example/main.dart:83:26)
/// “#4 _MyAppState.build (package:flutter_fimber_example/main.dart:83)

var stackTraceList = StackTrace.current.toString().split('\n');
if (stackTraceList.length > stackIndex) {
var logline = stackTraceList[stackIndex];
Expand All @@ -311,30 +364,33 @@ abstract class LogTree {
return LogLineInfo(tag: _defaultTag);
}
}
*/

static List<String> _getLineChunks(String stackinfo) {
var lineChunks = stackinfo.replaceAll("<anonymous closure>", "<ac>");
if (lineChunks.length > 6) {
var spaces = RegExp(r' +');
var lineParts = lineChunks.split(spaces);

return lineParts;
}
return <String>[];
}

/// Gets tag with [stackIndex],
/// how many steps in stacktrace should be taken to grab log call.
static String getTag({int stackIndex = 4}) {
var stackTraceList = StackTrace.current.toString().split('\n');
if (stackTraceList.length > stackIndex) {
var lineChunks =
stackTraceList[stackIndex].replaceAll("<anonymous closure>", "<ac>");
if (lineChunks.length > 6) {
var lineParts = lineChunks.split(' ');
if (lineParts.length > 8 && lineParts[6] == 'new') {
// constructor logging
return "${lineParts[6]} ${lineParts[7]}";
} else if (lineParts.length > 6) {
return lineParts[6];
} else {
return _defaultTag;
}
} else {
return _defaultTag;
var lineParts = _getLineChunks(stackTraceList[stackIndex]);
if (lineParts.length > 3 && lineParts[1] == 'new') {
// constructor logging
return "${lineParts[1]} ${lineParts[2]}";
} else if (lineParts.length > 1) {
return lineParts[1];
}
} else {
return _defaultTag; //default
}
return _defaultTag;
}

/// Gets tag with [stackIndex]
Expand Down Expand Up @@ -508,9 +564,8 @@ class CustomFormatTree extends LogTree {
}
}

@override

/// Logs a message with level/tag and optional stacktrace or exception.
@override
void log(String level, String msg,
{String? tag, dynamic? ex, StackTrace? stacktrace}) {
LogLineInfo logTag;
Expand Down
2 changes: 1 addition & 1 deletion fimber_io/lib/src/file_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class SizeRollingFileTree extends RollingFileTree {
.where((i) => (i >= 0) as bool)
.toList();
logListIndexes.sort();
print('log list indexes: $logListIndexes');
//print('log list indexes: $logListIndexes');
if (logListIndexes.isNotEmpty) {
var max = logListIndexes.last;
_fileIndex = max;
Expand Down
2 changes: 2 additions & 0 deletions fimber_io/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ environment:

dependencies:
fimber: "^0.6.6"
#fimber:
# path: ../fimber

dev_dependencies:
test: '^1.16.5'
Expand Down
12 changes: 11 additions & 1 deletion flutter_fimber/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 29
compileSdkVersion 33

namespace "com.magillus.flutterfimber"

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '11'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar

class FlutterFimberPlugin :FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
Expand Down Expand Up @@ -49,4 +48,4 @@ class FlutterFimberPlugin :FlutterPlugin, MethodCallHandler {
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}
}
13 changes: 13 additions & 0 deletions flutter_fimber/example/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
22 changes: 15 additions & 7 deletions flutter_fimber/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 29
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

lintOptions {
disable 'InvalidPackage'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.magillus.flutterfimberexample"
minSdkVersion 16
targetSdkVersion 29
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.magillus.flutterfimberexample">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
33 changes: 6 additions & 27 deletions flutter_fimber/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.magillus.flutterfimberexample">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_fimber_example"
android:icon="@mipmap/ic_launcher">

package="com.magillus.flutterfimberexample">
<application
android:label="flutterfimberexample"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand All @@ -32,15 +20,6 @@
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white"/>
<item android:drawable="@android:color/white" />

<!-- You can insert your own image assets here -->
<!-- <item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.

This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.magillus.flutterfimberexample">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
4 changes: 2 additions & 2 deletions flutter_fimber/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
1 change: 0 additions & 1 deletion flutter_fimber/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Nov 27 08:25:16 CST 2018
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
2 changes: 0 additions & 2 deletions flutter_fimber/example/android/settings_aar.gradle

This file was deleted.

Loading