package com.zepchat.core.util;

import android.util.Log;

import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
 * Created by Ziver on 2014-11-07.
 */
public class JavaLogger2LogCat extends Handler {
    @Override
    public void close() {}

    @Override
    public void flush() {}

    @Override
    public void publish(LogRecord record) {
        Level level = record.getLevel();

        if(level.equals(Level.SEVERE)) {
            Log.e(record.getSourceClassName(), record.getMessage(), record.getThrown());
        }
        else if(level.equals(Level.WARNING)) {
            Log.w(record.getSourceClassName(), record.getMessage(), record.getThrown());
        }
        else if(level.equals(Level.INFO)) {
            Log.i(record.getSourceClassName(), record.getMessage(), record.getThrown());
        }
        else if(level.equals(Level.FINE) || level.equals(Level.FINER) || level.equals(Level.FINEST)) {
            Log.d(record.getSourceClassName(), record.getMessage(), record.getThrown());
        }
    }
}
