2016-02-24 14:56:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the GNU Public License v3.0
|
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package at.bitfire.davdroid.log;
|
|
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
2016-03-18 14:40:05 +00:00
|
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
|
|
|
|
2016-02-24 14:56:30 +00:00
|
|
|
|
import java.util.logging.Handler;
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.LogRecord;
|
|
|
|
|
|
|
|
|
|
public class LogcatHandler extends Handler {
|
2016-03-18 14:40:05 +00:00
|
|
|
|
private static final int MAX_LINE_LENGTH = 3000;
|
2016-02-24 14:56:30 +00:00
|
|
|
|
public static final LogcatHandler INSTANCE = new LogcatHandler();
|
|
|
|
|
|
|
|
|
|
private LogcatHandler() {
|
|
|
|
|
super();
|
2016-02-24 22:08:19 +00:00
|
|
|
|
setFormatter(PlainTextFormatter.LOGCAT);
|
2016-02-24 14:56:30 +00:00
|
|
|
|
setLevel(Level.ALL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-02-24 22:08:19 +00:00
|
|
|
|
public void publish(LogRecord r) {
|
2016-03-18 14:40:05 +00:00
|
|
|
|
String text = getFormatter().format(r);
|
2016-02-24 22:08:19 +00:00
|
|
|
|
int level = r.getLevel().intValue();
|
2016-02-24 14:56:30 +00:00
|
|
|
|
|
2016-03-18 14:40:05 +00:00
|
|
|
|
int end = text.length();
|
|
|
|
|
for (int pos = 0; pos < end; pos += MAX_LINE_LENGTH) {
|
|
|
|
|
String line = text.substring(pos, NumberUtils.min(pos + MAX_LINE_LENGTH, end));
|
|
|
|
|
|
|
|
|
|
if (level >= Level.SEVERE.intValue())
|
|
|
|
|
Log.e(r.getLoggerName(), line);
|
|
|
|
|
else if (level >= Level.WARNING.intValue())
|
|
|
|
|
Log.w(r.getLoggerName(), line);
|
|
|
|
|
else if (level >= Level.CONFIG.intValue())
|
|
|
|
|
Log.i(r.getLoggerName(), line);
|
|
|
|
|
else if (level >= Level.FINER.intValue())
|
|
|
|
|
Log.d(r.getLoggerName(), line);
|
|
|
|
|
else
|
|
|
|
|
Log.v(r.getLoggerName(), line);
|
|
|
|
|
}
|
2016-02-24 14:56:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void flush() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void close() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|