diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 3ef0e6fa..30f5e1be 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 3550d645..30aa626c 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -25,37 +25,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
deleted file mode 100644
index 79ee123c..00000000
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 97626ba4..00000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7f..35eb1ddf 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index e1a1ed21..83045b76 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,11 +1,11 @@
buildscript {
- ext.kotlinVersion = '1.2.31'
+ ext.kotlinVersion = '1.3.31'
repositories {
google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.1.0'
+ classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
@@ -59,4 +59,4 @@ ext.deps = [
json : "org.json:json:20160810",
supportAnnotations: "com.android.support:support-annotations:27.1.0",
kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
-]
\ No newline at end of file
+]
diff --git a/logger/src/main/java/com/orhanobut/logger/CsvFormatStrategy.java b/logger/src/main/java/com/orhanobut/logger/CsvFormatStrategy.java
index 57a0cedd..c4533ef0 100644
--- a/logger/src/main/java/com/orhanobut/logger/CsvFormatStrategy.java
+++ b/logger/src/main/java/com/orhanobut/logger/CsvFormatStrategy.java
@@ -7,6 +7,7 @@
import android.support.annotation.Nullable;
import java.io.File;
+import java.nio.file.InvalidPathException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
@@ -38,6 +39,10 @@ private CsvFormatStrategy(@NonNull Builder builder) {
tag = builder.tag;
}
+ @NonNull public static Builder newBuilder(String foldername, int maxsize) {
+ return new Builder(foldername, maxsize);
+ }
+
@NonNull public static Builder newBuilder() {
return new Builder();
}
@@ -88,14 +93,31 @@ private CsvFormatStrategy(@NonNull Builder builder) {
}
public static final class Builder {
- private static final int MAX_BYTES = 500 * 1024; // 500K averages to a 4000 lines per file
+ private static int MAX_BYTES = 500 * 1024; // default size 500K averages to a 4000 lines per file
Date date;
SimpleDateFormat dateFormat;
LogStrategy logStrategy;
String tag = "PRETTY_LOGGER";
+ String folderName = "logger"; //default folder name
+
+ // Default constructor, will use logger as folder name and 500K as default size
+ private Builder(){
+
+ }
- private Builder() {
+ private Builder(String foldername, int maxsize) {
+ if (foldername == null || foldername.length() == 0) {
+ //folder name seems to be invalid, throw an exception (just basic check, there could be invalid characters for folder name those will throw exception at time of writing
+ throw new IllegalArgumentException("Folder name you have provided seems to be invalid. " + foldername);
+ }
+ if(maxsize <= 0)
+ {
+ throw new IllegalArgumentException("File max size must be greater than 0, you have provided " + maxsize);
+ }
+
+ folderName = foldername;
+ MAX_BYTES = maxsize;
}
@NonNull public Builder date(@Nullable Date val) {
@@ -127,7 +149,7 @@ private Builder() {
}
if (logStrategy == null) {
String diskPath = Environment.getExternalStorageDirectory().getAbsolutePath();
- String folder = diskPath + File.separatorChar + "logger";
+ String folder = diskPath + File.separatorChar + folderName;
HandlerThread ht = new HandlerThread("AndroidFileLogger." + folder);
ht.start();
diff --git a/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java b/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java
index 2d4fb5ce..df639098 100644
--- a/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java
+++ b/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java
@@ -13,10 +13,16 @@ public class DiskLogAdapter implements LogAdapter {
@NonNull private final FormatStrategy formatStrategy;
+
public DiskLogAdapter() {
formatStrategy = CsvFormatStrategy.newBuilder().build();
}
+ public DiskLogAdapter(String foldername, int maxfilesize)
+ {
+ formatStrategy = CsvFormatStrategy.newBuilder(foldername, maxfilesize).build();
+ }
+
public DiskLogAdapter(@NonNull FormatStrategy formatStrategy) {
this.formatStrategy = checkNotNull(formatStrategy);
}
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 0ae2fea2..accc1a22 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -2,6 +2,7 @@
+
diff --git a/sample/src/main/java/com/orhanobut/sample/MainActivity.java b/sample/src/main/java/com/orhanobut/sample/MainActivity.java
index c2bf2f2d..55feed27 100644
--- a/sample/src/main/java/com/orhanobut/sample/MainActivity.java
+++ b/sample/src/main/java/com/orhanobut/sample/MainActivity.java
@@ -82,5 +82,10 @@ protected void onCreate(Bundle savedInstanceState) {
Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
Logger.w("my log message with my tag");
+
+ Logger.clearLogAdapters();
+ Logger.addLogAdapter(new DiskLogAdapter("customfoldername", 2097152)); //create a DiskLogAdapter with folder name customfoldername and 2MB max file size
+
+ Logger.i("Info log written in custom folder");
}
}