Skip to content

Commit

Permalink
Optimize Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Mar 9, 2023
1 parent 173643e commit 99af0a7
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 8 deletions.
1 change: 0 additions & 1 deletion core/src/com/isharryh/arkpets/ArkPets.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public ArkPets(String $title) {
public void create() {
// When the APP was created
// 1.App setup
Gdx.app.setLogLevel(3);
Gdx.app.log("event", "AP:Create");
Gdx.input.setInputProcessor(this);
config = Objects.requireNonNull(ArkConfig.getConfig());
Expand Down
15 changes: 9 additions & 6 deletions desktop/src/com/isharryh/arkpets/DesktopLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
*/
package com.isharryh.arkpets;

import com.isharryh.arkpets.utils.ArgPending;
import javafx.application.Application;


/** The entrance of the whole program, also the bootstrap for ArkHomeFX.
* @see com.isharryh.arkpets.ArkHomeFX
*/
public class DesktopLauncher {
public static void main (String[] arg) {
if (arg.length > 0 && arg[0].equals("--direct-start")) {
EmbeddedLauncher.main(arg);
return;
}
public static void main (String[] args) {
new ArgPending("--direct-start", args) {
protected void process(String command, String addition) {
EmbeddedLauncher.main(args);
System.exit(0);
}
};
// Java FX bootstrap
Application.launch(ArkHomeFX.class, arg);
Application.launch(ArkHomeFX.class, args);
System.exit(0);
}
}
21 changes: 20 additions & 1 deletion desktop/src/com/isharryh/arkpets/EmbeddedLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
*/
package com.isharryh.arkpets;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Color;

import com.isharryh.arkpets.utils.ArgPending;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;

Expand All @@ -17,7 +19,7 @@
public class EmbeddedLauncher {
// Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument

public static void main (String[] arg) {
public static void main (String[] args) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
// Configure FPS
config.setForegroundFPS(30);
Expand All @@ -39,6 +41,23 @@ public static void main (String[] arg) {
config.setWindowPosition(0, 0);
// Instantiate the App
Lwjgl3Application app = new Lwjgl3Application(new ArkPets(TITLE), config);
// Set logging level
app.setLogLevel(Application.LOG_DEBUG);
new ArgPending("--quiet", args) {
protected void process(String command, String addition) {
app.setLogLevel(Application.LOG_ERROR);
}
};
new ArgPending("--info", args) {
protected void process(String command, String addition) {
app.setLogLevel(Application.LOG_INFO);
}
};
new ArgPending("--debug", args) {
protected void process(String command, String addition) {
app.setLogLevel(Application.LOG_DEBUG);
}
};
}

private static String applyWindowTitle() {
Expand Down
64 changes: 64 additions & 0 deletions desktop/src/com/isharryh/arkpets/utils/ArgPending.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/** Copyright (c) 2022-2023, Harry Huang
* At GPL-3.0 License
*/
package com.isharryh.arkpets.utils;

abstract public class ArgPending {
private static final String argPrefix = "-";
private final String pattern;

/** Initialize an Argument Pending instance.
* @param pattern The specified argument string to be match.
*/
public ArgPending(String pattern) {
this.pattern = pattern;
}

/** Initialize an Argument Pending instance and deal a given arguments list.
* @param pattern The specified argument string to be match.
* @param args The given arguments list to be dealt.
*/
public ArgPending(String pattern, String[] args) {
this.pattern = pattern;
this.judge(args);
}

/** Deal a given arguments list.
* If the pattern specified before matches one of the arguments, the method {@code process()} will be invoked.
* @param args The given arguments list to be dealt.
* @return Whether the pattern specified before matches one of the arguments.
*/
public boolean judge(String[] args) {
if (args.length == 0)
return false;
String addition = null;
String command = null;
boolean specified = false;

for (String arg: args) {
if (arg != null) {
if (specified) {
if (arg.indexOf(argPrefix) != 0)
addition = arg;
else
break;
} else if (arg.equals(pattern)) {
command = arg;
specified = true;
}
}
}

if (command != null) {
process(command, addition);
return true;
}
return false;
}

/** To process the argument.
* @param command The argument string.
* @param addition The additional string which is nullable.
*/
abstract protected void process(String command, String addition);
}

0 comments on commit 99af0a7

Please sign in to comment.