104 lines
2.9 KiB
Java
104 lines
2.9 KiB
Java
package com.orhanobut.logger;
|
|
|
|
import android.os.Environment;
|
|
import android.os.HandlerThread;
|
|
import android.text.TextUtils;
|
|
import com.orhanobut.logger.DiskLogStrategy;
|
|
import java.io.File;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Locale;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class CsvFormatStrategy implements FormatStrategy {
|
|
private static final String e = System.getProperty("line.separator");
|
|
private final Date a;
|
|
private final SimpleDateFormat b;
|
|
private final LogStrategy c;
|
|
private final String d;
|
|
|
|
public static final class Builder {
|
|
Date a;
|
|
SimpleDateFormat b;
|
|
LogStrategy c;
|
|
String d;
|
|
private String e;
|
|
|
|
public Builder a(SimpleDateFormat simpleDateFormat) {
|
|
this.b = simpleDateFormat;
|
|
return this;
|
|
}
|
|
|
|
public Builder b(String str) {
|
|
this.d = str;
|
|
return this;
|
|
}
|
|
|
|
private Builder() {
|
|
this.d = "PRETTY_LOGGER";
|
|
}
|
|
|
|
public Builder a(String str) {
|
|
this.e = str;
|
|
return this;
|
|
}
|
|
|
|
public CsvFormatStrategy a() {
|
|
if (this.a == null) {
|
|
this.a = new Date();
|
|
}
|
|
if (this.b == null) {
|
|
this.b = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS", Locale.UK);
|
|
}
|
|
if (this.c == null) {
|
|
if (TextUtils.isEmpty(this.e)) {
|
|
this.e = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separatorChar + "logger";
|
|
}
|
|
HandlerThread handlerThread = new HandlerThread("AndroidFileLogger." + this.e);
|
|
handlerThread.start();
|
|
this.c = new DiskLogStrategy(new DiskLogStrategy.WriteHandler(handlerThread.getLooper(), this.e, 512000));
|
|
}
|
|
return new CsvFormatStrategy(this);
|
|
}
|
|
}
|
|
|
|
public static Builder a() {
|
|
return new Builder();
|
|
}
|
|
|
|
private CsvFormatStrategy(Builder builder) {
|
|
Utils.a(builder);
|
|
this.a = builder.a;
|
|
this.b = builder.b;
|
|
this.c = builder.c;
|
|
this.d = builder.d;
|
|
}
|
|
|
|
@Override // com.orhanobut.logger.FormatStrategy
|
|
public void a(int i, String str, String str2) {
|
|
Utils.a(str2);
|
|
String a = a(str);
|
|
this.a.setTime(System.currentTimeMillis());
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(this.b.format(this.a));
|
|
sb.append(",");
|
|
sb.append(Utils.a(i));
|
|
sb.append(",");
|
|
sb.append(a);
|
|
if (str2.contains(e)) {
|
|
str2 = str2.replaceAll(e, " <br> ");
|
|
}
|
|
sb.append(",");
|
|
sb.append(str2);
|
|
sb.append(e);
|
|
this.c.a(i, a, sb.toString());
|
|
}
|
|
|
|
private String a(String str) {
|
|
if (!Utils.a((CharSequence) str) && !Utils.a(this.d, str)) {
|
|
return this.d + "-" + str;
|
|
}
|
|
return this.d;
|
|
}
|
|
}
|