/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  android.util.Log
 *  java.io.IOException
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.Throwable
 *  java.net.DatagramPacket
 *  java.net.DatagramSocket
 *  java.net.InetAddress
 */
package com.google.code.microlog4android.appender;

import android.util.Log;
import com.google.code.microlog4android.Level;
import com.google.code.microlog4android.appender.AbstractAppender;
import com.google.code.microlog4android.format.Formatter;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class DatagramAppender
extends AbstractAppender {
    public static final String DEFAULT_HOST = "127.0.0.1";
    private static final String TAG = "Microlog.DatagramAppender";
    private InetAddress address;
    private DatagramPacket datagramPacket;
    private DatagramSocket datagramSocket;
    private String host = "127.0.0.1";
    private int port;

    @Override
    public void clear() {
    }

    @Override
    public void close() throws IOException {
        if (this.datagramSocket != null) {
            this.datagramSocket.close();
        }
        this.logOpen = false;
    }

    @Override
    public void doLog(String string2, String string3, long l, Level level, Object object, Throwable throwable) {
        if (this.logOpen && this.formatter != null) {
            this.sendMessage(this.formatter.format(string2, string3, l, level, object, throwable));
        }
    }

    @Override
    public long getLogSize() {
        return -1;
    }

    @Override
    public void open() throws IOException {
        this.datagramSocket = new DatagramSocket();
        this.address = InetAddress.getByName((String)this.host);
        this.datagramPacket = new DatagramPacket(new byte[0], 0, this.address, this.port);
        this.logOpen = true;
    }

    public void sendMessage(String string2) {
        byte[] arrby = string2.getBytes();
        this.datagramPacket.setData(arrby);
        try {
            this.datagramSocket.send(this.datagramPacket);
            return;
        }
        catch (IOException var3_3) {
            Log.e((String)"Microlog.DatagramAppender", (String)("Failed to send datagram log " + (Object)var3_3));
            return;
        }
    }

    public void setPort(int n) {
        this.port = n;
    }
}

