2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.core;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
2020-05-03 01:46:07 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
public class ErrorLog implements DatabaseLoggable {
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ErrorLog.class);
|
|
|
|
private static final String QUERY = "INSERT INTO emulator_errors (timestamp, version, build_hash, type, stacktrace) VALUES (?, ?, ?, ?, ?)";
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2019-05-14 21:39:35 +02:00
|
|
|
public final String version;
|
|
|
|
public final String buildHash;
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
public final int timeStamp;
|
|
|
|
public final String type;
|
|
|
|
public final String stackTrace;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public ErrorLog(String type, Throwable e) {
|
2019-05-14 21:39:35 +02:00
|
|
|
this.version = Emulator.version;
|
|
|
|
this.buildHash = Emulator.version;
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
this.timeStamp = Emulator.getIntUnixTimestamp();
|
|
|
|
this.type = type;
|
|
|
|
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
e.printStackTrace(pw);
|
|
|
|
this.stackTrace = sw.toString();
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
pw.close();
|
|
|
|
sw.close();
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (IOException e1) {
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.error("Exception caught", e1);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public ErrorLog(String type, String message) {
|
2019-05-14 21:39:35 +02:00
|
|
|
this.version = Emulator.version;
|
|
|
|
this.buildHash = Emulator.build;
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
this.timeStamp = Emulator.getIntUnixTimestamp();
|
|
|
|
this.type = type;
|
|
|
|
this.stackTrace = message;
|
|
|
|
}
|
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
@Override
|
|
|
|
public String getQuery() {
|
|
|
|
return QUERY;
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void log(PreparedStatement statement) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.setInt(1, this.timeStamp);
|
2019-05-14 21:39:35 +02:00
|
|
|
statement.setString(2, this.version);
|
|
|
|
statement.setString(3, this.buildHash);
|
|
|
|
statement.setString(4, this.type);
|
|
|
|
statement.setString(5, this.stackTrace);
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.addBatch();
|
|
|
|
}
|
|
|
|
}
|