CommonCore/src/de/steamwar/sql/SWException.java

62 Zeilen
2.1 KiB
Java

2022-09-20 16:41:07 +02:00
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import java.io.File;
2022-10-29 13:19:36 +02:00
import java.sql.Timestamp;
2022-09-20 16:41:07 +02:00
@AllArgsConstructor
public class SWException {
2022-10-29 12:42:41 +02:00
public static void init() {
// force class initialialisation
}
2022-09-20 16:41:07 +02:00
private static final String CWD = System.getProperty("user.dir");
private static final String SERVER_NAME = new File(CWD).getName();
private static final Table<SWException> table = new Table<>(SWException.class, "Exception");
2022-10-29 13:19:36 +02:00
private static final Statement insert = table.insertFields("server", "message", "stacktrace");
2022-09-20 16:41:07 +02:00
2022-11-02 22:38:21 +01:00
@Field(keys = {Table.PRIMARY}, autoincrement = true)
2022-10-29 13:19:36 +02:00
private final int id;
@Field(def = "CURRENT_TIMESTAMP")
private final Timestamp time;
2022-09-20 16:41:07 +02:00
@Field
private final String server;
@Field
private final String message;
@Field
private final String stacktrace;
public static void log(String message, String stacktrace){
StringBuilder msgBuilder = new StringBuilder(message);
SQLWrapper.impl.additionalExceptionMetadata(msgBuilder);
msgBuilder.append("\nCWD: ").append(CWD);
insert.update(SERVER_NAME, msgBuilder.toString(), stacktrace);
}
}