Commit 0a80a0c7 authored by Drahomír Karchňák's avatar Drahomír Karchňák

#779 WIP - Added log file for desktop version.

parent 56018e7f
......@@ -29,6 +29,10 @@ import net.engio.mbassy.bus.error.IPublicationErrorHandler;
import net.engio.mbassy.bus.error.PublicationError;
import net.engio.mbassy.listener.Handler;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
......@@ -38,6 +42,7 @@ import java.util.concurrent.CountDownLatch;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.game.ranksystem.UserRankManager;
import cz.nic.tablexia.loader.TablexiaAbstractFileManager;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationAvatarManager;
import cz.nic.tablexia.loader.application.TablexiaBadgesManager;
......@@ -54,6 +59,7 @@ import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.util.CameraOpener;
import cz.nic.tablexia.util.IFileSystemManager;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.TeeStream;
import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.util.ui.button.StandardTablexiaButton;
import cz.nic.tablexia.util.ui.QRCodeScanner;
......@@ -97,6 +103,8 @@ public class Tablexia extends TablexiaApplication {
private static final boolean LOADER_ERROR_DIALOG_HIDE_ANIMATION = false;
private static final String LOG_FILE_NAME = "log.log";
private static IConnectionManager connectionManager;
private static CameraOpener cameraOpener;
private static IFileSystemManager fileSystemManager;
......@@ -150,6 +158,20 @@ public class Tablexia extends TablexiaApplication {
TablexiaRaven.start(DSN);
}
if(TablexiaSettings.getInstance().getBuildType().isLogFile()) {
try {
File file = new File(TablexiaAbstractFileManager.RootStorageType.LOCAL.getStoragePath(), LOG_FILE_NAME);
if(file.exists()) file.mkdirs();
PrintStream stream = new PrintStream(new FileOutputStream(file));
TeeStream teeStream = new TeeStream(System.out, stream);
System.setOut(new PrintStream(teeStream));
} catch (FileNotFoundException e) {
Log.info(getClass(), "Cannot create a log file!");
e.printStackTrace();
}
}
// register error handler for exceptions in event bus handler methods
ApplicationBus.getInstance().addErrorHandler(new IPublicationErrorHandler() {
@Override
......
......@@ -123,10 +123,10 @@ public class TablexiaSettings {
public enum BuildType {
// boxes aInfo sInfo dMenu btName bReport debugBtn syncDTB
RELEASE (1, "release", false, false, false, false, false, true, false, true, Log.TablexiaLogLevel.ERROR),
DEBUG (2, "debug", false, true, true, true, true, true, true, true, Log.TablexiaLogLevel.DEBUG),
DEVEL (3, "devel", true, true, true, true, true, false, true, true, Log.TablexiaLogLevel.DEBUG),
ITEST (4, "itest", false, true, true, false, true, false, false, false, Log.TablexiaLogLevel.DEBUG);
RELEASE (1, "release", false, false, false, false, false, true, false, true, false, Log.TablexiaLogLevel.ERROR),
DEBUG (2, "debug", false, true, true, true, true, true, true, true, true, Log.TablexiaLogLevel.DEBUG),
DEVEL (3, "devel", true, true, true, true, true, false, true, true, true, Log.TablexiaLogLevel.DEBUG),
ITEST (4, "iTest", false, true, true, false, true, false, false, false, false, Log.TablexiaLogLevel.DEBUG);
private final static BuildType FALLBACK_VARIANT = BuildType.DEVEL;
......@@ -140,10 +140,11 @@ public class TablexiaSettings {
private boolean bugReport;
private boolean showDebugButtons;
private boolean syncWithDTB;
private boolean logFile;
private final Log.TablexiaLogLevel logLevel;
BuildType(int id, String key, boolean boundingBoxes, boolean applicationInfo, boolean screenInfo, boolean debugMenu, boolean showBuildTypeInName, boolean bugReport, boolean showDebugButtons, boolean syncWithDTB, Log.TablexiaLogLevel logLevel) {
BuildType(int id, String key, boolean boundingBoxes, boolean applicationInfo, boolean screenInfo, boolean debugMenu, boolean showBuildTypeInName, boolean bugReport, boolean showDebugButtons, boolean syncWithDTB, boolean logFile, Log.TablexiaLogLevel logLevel) {
this.id = id;
this.key = key;
this.boundingBoxes = boundingBoxes;
......@@ -154,6 +155,7 @@ public class TablexiaSettings {
this.bugReport = bugReport;
this.showDebugButtons = showDebugButtons;
this.syncWithDTB = syncWithDTB;
this.logFile = logFile;
this.logLevel = logLevel;
}
......@@ -197,6 +199,8 @@ public class TablexiaSettings {
return syncWithDTB;
}
public boolean isLogFile() { return logFile; }
public Log.TablexiaLogLevel getLogLevel() {
return logLevel;
}
......
/*
* Copyright (C) 2016 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.nic.tablexia.util;
import java.io.IOException;
import java.io.OutputStream;
public class TeeStream extends OutputStream {
private OutputStream out, tee;
public TeeStream(OutputStream out, OutputStream tee) {
if (out == null)
throw new NullPointerException();
else if (tee == null)
throw new NullPointerException();
this.out = out;
this.tee = tee;
}
@Override
public void write(int b) throws IOException {
out.write(b);
tee.write(b);
}
@Override
public void write(byte[] b) throws IOException {
out.write(b);
tee.write(b);
}
@Override
public void flush() throws IOException {
out.flush();
tee.flush();
}
@Override
public void close() throws IOException {
out.close();
tee.close();
}
}
\ No newline at end of file
......@@ -25,7 +25,10 @@ import com.jcabi.manifests.Manifests;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Locale;
import cz.nic.tablexia.Tablexia;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment