Skip to content

Commit

Permalink
code documentation added for the builders
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Feb 13, 2017
1 parent ea1093c commit 7b664ba
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 33 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ dependencies {
// modules (OPTIONAL)
compile 'com.github.MFlisar.Lumberjack:lumberjack-filelogger:1.3'
compile 'com.github.MFlisar.Lumberjack:lumberjack-notification:1.3'
debugCompile project(':lumberjack-overlay')
releaseCompile project(':lumberjack-overlay-noop')
// ALTERNATIVELY you can add ALL modules at once like following
// compile 'com.github.MFlisar:Lumberjack:1.3'
Expand All @@ -43,7 +45,7 @@ dependencies {

###Example

This is what the demo setup will print out (to your file, to the notification, to console). It has pretty printing enabled and prints first 5 values of an array automatically. It as well prints caller class and group combined as tag. The demo shows that
This is what the demo setup will print out (to your file, to the notification, to console, to the overlay). It has pretty printing enabled and prints first 5 values of an array automatically. It as well prints caller class and group combined as tag. The demo shows that

* arrays are printed automatically
* custom classes are automatically formatter to the custom formatter you have registered, no matter if the classes are printed inside an array or as a simple value
Expand Down Expand Up @@ -95,8 +97,7 @@ The overlay logger is based on Hannes Dorfmann's DebugOverlay: https://github.co
###Missing

* Notification Logger
* An activity that can be launched via the notification (that shows the logs and offers advanced filter options)
* filter: errors only
* overlay logger
* demo gif
* noop für overlay logger to avoid the overlay manifest permission
* An activity that can be launched via the notification (that shows the logs and offers advanced filter options)
* filter: errors only
* Overlay Logger
* filter: errors only
13 changes: 8 additions & 5 deletions demo/app/src/main/java/com/michaelflisar/lumberjack/demo/L.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public String log(MainActivity.TestClass item, boolean logInList) {
});

// some test logs...
L.d(G_TEST, "initLumberjack fertig");
L.d(G_TEST, "LogFiles: %s", FileLoggingUtil.getAllExistingLogFiles(FILE_LOG_SETUP));
L.d(G_TEST1, "initLumberjack fertig");
L.d(G_TEST2, "LogFiles: %s", FileLoggingUtil.getAllExistingLogFiles(FILE_LOG_SETUP));
}

public static void initOverlayLogger(Activity activity)
Expand All @@ -78,19 +78,21 @@ public static void handleOverlayPermissionDialogResult(int requestCode, int resu
// we know that the 4th tree is the overlay logger, so we just hand on the data
boolean success = ((OverlayLoggingTree)Timber.forest().get(3)).checkRequestPermissionResult(requestCode, resultCode, data);

L.d(G_TEST, "Overlay permission granted: %b", success);
L.d(G_TEST1, "Overlay permission granted: %b", success);
}

// -----------------------------
// Advanced - Groups
// -----------------------------

// Groups
public static final ILogGroup G_TEST = L.createGroup("TEST-GROUP");
public static final ILogGroup G_TEST1 = L.createGroup("TEST-GROUP 1");
public static final ILogGroup G_TEST2 = L.createGroup("TEST-GROUP 2");

public static final ArrayList<ILogGroup> LOG_GROUPS = new ArrayList<ILogGroup>() {
{
add(G_TEST);
add(G_TEST1);
add(G_TEST2);
}
};

Expand All @@ -108,6 +110,7 @@ public static void handleOverlayPermissionDialogResult(int requestCode, int resu
.withTitle("Demo Logger")
//.withBigIcon(R.mipmap.ic_launcher_default)
.withNotificationId(150)
.withButtonIntentRequestCodeBase(250)
.withFilters(LOG_GROUPS);

// -----------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.Arrays;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private int mCount = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (savedInstanceState != null)
mCount = savedInstanceState.getInt("mCount");

findViewById(R.id.btLog).setOnClickListener(this);

// here we can ask for the permission, so we init the overlay logger in here
// make sure to pass on the result of the permission dialog to the overlay logger!
L.initOverlayLogger(this);
Expand All @@ -30,13 +37,13 @@ protected void onCreate(Bundle savedInstanceState) {
L.d("Test array log: %s", new ArrayList<>(Arrays.asList("array value 1", "array value 2")));

// Test 3: a few logs with usage of groups
L.d(L.G_TEST, "Test message in test group");
L.d(L.G_TEST, "Test message in test group, value=%d", 999);
L.d(L.G_TEST1, "Test message in test group");
L.d(L.G_TEST1, "Test message in test group, value=%d", 999);

// Test 4: Disable a group, log to this group and see, that nothing is logged and enable group again
L.disableLogGroup(L.G_TEST);
L.e(L.G_TEST, "This message should NOT appear anywhere because the group is disabled!");
L.enableLogGroup(L.G_TEST);
L.disableLogGroup(L.G_TEST1);
L.e(L.G_TEST1, "This message should NOT appear anywhere because the group is disabled!");
L.enableLogGroup(L.G_TEST1);

// Test 5 - custom object formatting
// we have registered a custom formatter for our TestClass, so we can DIRECTLY pass TestClasses for any string paramter and lumberjack will take care of it!
Expand All @@ -50,6 +57,20 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putInt("mCount", mCount);
}

@Override
public void onClick(View view)
{
mCount++;
L.d("Button clicked: %d", mCount);
}

public static class TestClass
{
public int x;
Expand Down
7 changes: 7 additions & 0 deletions demo/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

<Button
android:id="@+id/btLog"
android:layout_centerInParent="true"
android:text="Add log message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,88 @@ public FileLoggingSetup(Context context)
mFolder = context.getFileStreamPath("").getAbsolutePath();
}

/**
* define a custom path for the folder, in which you want to create your log files
* DEFAULT: the apps cache directory
*
* @param folderPath The path of the folder
*/
public FileLoggingSetup withFolder(String folderPath)
{
mFolder = folderPath;
return this;
}

/**
* define a custom basic file name for your log files
* DEFAULT: log
*
* @param fileName The basic file name of your log files
*/
public FileLoggingSetup withFileName(String fileName)
{
mFileName = fileName;
return this;
}

/**
* define a custom file extension for your log files
* DEFAULT: log
*
* @param fileExtension The file extension of your log files
*/
public FileLoggingSetup withFileExtension(String fileExtension)
{
mFileExtension = fileExtension;
return this;
}

/**
* define a custom log file pattern
* DEFAULT: 7
*
* @param logsToKeep number of log files to keep
*/
public FileLoggingSetup withLogsToKeep(int logsToKeep)
{
mLogsToKeep = logsToKeep;
return this;
}

/**
* define a custom file logger format
* Refer to https://github.com/tony19/logback-android and https://www.slf4j.org/ for more infos
* DEFAULT: %d{HH:mm:ss.SSS} %logger{36} %msg%n
*
* @param pattern the log pattern
*/
public FileLoggingSetup withPattern(String pattern)
{
mLogPattern = pattern;
return this;
}

/**
* define the mode you want to use
* Select between {@link Mode#DateFiles} and {@link Mode#NumberedFiles}
* {@link Mode#DateFiles} will create a log file per day
* {@link Mode#NumberedFiles} will create a new log file after the size defined via {@link FileLoggingSetup#withNumberedFileSizeLimit(String)} is reached
*
* @param mode the mode you want
*/
public FileLoggingSetup withMode(Mode mode)
{
mMode = mode;
return this;
}

/**
* define the size limit for the file logger with mode {@link Mode#NumberedFiles}
* you can use 1KB, 1MB and similar strings
* DEFAULT: 1MB
*
* @param size the size
*/
public FileLoggingSetup withNumberedFileSizeLimit(String size)
{
mNumberedFileSizeLimit = size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,108 @@ public class NotificationLoggingSetup
Integer mVibrationLogLevel = null;
Integer mBeepLogLevel = null;

/**
* Constructor of the setup
*
* @param smallIcon the small notification icon
*/
public NotificationLoggingSetup(int smallIcon)
{
mSmallIcon = smallIcon;
}

/**
* define a custom notification title
* DEFAULT: Logger
*
* @param title the notification title
*/
public NotificationLoggingSetup withTitle(String title)
{
mTitle = title;
return this;
}

/**
* define a custom big notification icon
* DEFAULT: NONE
*
* @param icon the big notification icon
*/
public NotificationLoggingSetup withBigIcon(int icon)
{
mBigIcon = icon;
return this;
}

/**
* define a custom notification id to avoid problems with multiple loggers or other notifications
* DEFAULT: 100
*
* @param id the notification id
*/
public NotificationLoggingSetup withNotificationId(int id)
{
mNotificationId = id;
return this;
}

/**
* define a custom base id for the intents that will be broadcasted via the notification button clicks
* This number and the following 9 numbers will be used by the notification for handling the button clicks!
* DEFAULT: 100
*
* @param requestCodeBase the first request code for the notifications buttons
*/
public NotificationLoggingSetup withButtonIntentRequestCodeBase(int requestCodeBase)
{
mButtonIntentRequestCodeBase = requestCodeBase;
return this;
}

/**
* define a custom priority for the notification
* DEFAULT: {@link Notification#PRIORITY_MAX}
*
* @param priority the notifications priority
*/
public NotificationLoggingSetup withPriority(int priority)
{
mPriority = priority;
return this;
}

/**
* hand on all log groups you want this logger be able to skip through
* DEFAULT: NONE, because the groups are defined by you
*
* @param filters a list of all your log groups
*/
public NotificationLoggingSetup withFilters(ArrayList<ILogGroup> filters)
{
mFilters = filters;
return this;
}

public NotificationLoggingSetup withVibrateOn(int logLevel)
/**
* enable vibration whenever a log message is written to the notification
* DEFAULT: null (disabled)
*
* @param logLevel the minimum log level a log message must have to activate the vibration
*/
public NotificationLoggingSetup withVibrateOn(Integer logLevel)
{
mVibrationLogLevel = logLevel;
return this;
}

public NotificationLoggingSetup withBeepOn(int logLevel)
/**
* enable a beep whenever a log message is written to the notification
* DEFAULT: null (disabled)
*
* @param logLevel the minimum log level a log message must have to activate the beep
*/
public NotificationLoggingSetup withBeepOn(Integer logLevel)
{
mBeepLogLevel = logLevel;
return this;
Expand Down
Loading

0 comments on commit 7b664ba

Please sign in to comment.