0

Запись лога в файл переложили на логгер

This commit is contained in:
2017-05-12 11:42:08 +03:00
parent fa501d1cc5
commit 2d1702ce5f
4 changed files with 15 additions and 62 deletions

3
.gitignore vendored
View File

@@ -26,4 +26,5 @@ target/
lib/
baseq2/
baseq2.rar
TODO.txt
TODO.txt
qconsole.log

View File

@@ -4,10 +4,14 @@
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%-5level] (%t) \{%logger{36}\} %msg%n"/>
</Console>
<File name="File" fileName="qconsole.log" append="true">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%-5level] (%t) \{%logger{36}\} %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>

View File

@@ -27,10 +27,10 @@ import lwjake2.server.SV_MAIN;
import lwjake2.sys.Sys;
import lwjake2.util.PrintfFormat;
import lwjake2.util.Vargs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* Com
@@ -38,7 +38,7 @@ import java.io.RandomAccessFile;
*/
public final class Com
{
private static final Logger logger = LoggerFactory.getLogger(Com.class);
static String debugContext = "";
static String _debugContext = "";
@@ -356,50 +356,12 @@ public final class Com
Console.Print(msg);
// also echo to debugging console
Sys.ConsoleOutput(msg);
// logfile
if (Globals.logfile_active != null && Globals.logfile_active.value != 0)
{
String name;
if (Globals.logfile == null)
{
name= FS.Gamedir() + "/qconsole.log";
if (Globals.logfile_active.value > 2)
try
{
Globals.logfile = new RandomAccessFile(name, "rw");
Globals.logfile.seek(Globals.logfile.length());
}
catch (Exception e)
{
// TODO: do quake2 error handling!
e.printStackTrace();
}
else
try
{
Globals.logfile= new RandomAccessFile(name, "rw");
}
catch (FileNotFoundException e1)
{
// TODO: do quake2 error handling!
e1.printStackTrace();
}
}
if (Globals.logfile != null)
try
{
Globals.logfile.writeChars(msg);
}
catch (IOException e)
{
// TODO: do quake2 error handling!
e.printStackTrace();
}
if (Globals.logfile_active.value > 1); // do nothing
// fflush (logfile); // force it to save every time
while (msg.startsWith("\n")) { msg = msg.substring(1); }
while (msg.endsWith("\n")) { msg = msg.substring(0, msg.lastIndexOf("\n")); }
while (msg.endsWith("\r")) { msg = msg.substring(0, msg.lastIndexOf("\r")); }
msg = msg.trim();
if (!msg.isEmpty()) {
logger.info(msg);
}
}

View File

@@ -229,18 +229,4 @@ public final class Sys extends Defines {
return null;
}
public static void ConsoleOutput(String msg) {
if (Globals.nostdout != null && Globals.nostdout.value != 0)
return;
while (msg.startsWith("\n")) {
msg = msg.substring(1);
}
while (msg.endsWith("\n")) {
msg = msg.substring(0, msg.lastIndexOf("\n"));
}
logger.info(msg);
}
}