Skip to content

Commit

Permalink
Switch log from slf4j to java logging
Browse files Browse the repository at this point in the history
  • Loading branch information
GZYangKui committed Jan 12, 2023
1 parent 164d250 commit bc51e53
Show file tree
Hide file tree
Showing 24 changed files with 242 additions and 112 deletions.
13 changes: 1 addition & 12 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,7 @@
<artifactId>nes4j-bin</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/cn/navclub/nes4j/app/INes.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import javafx.application.Application;

import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;


import java.util.ResourceBundle;

@Slf4j
public class INes extends Application {
public final static EventBus eventBus;
public static final ResourceBundle RESOURCE_BUNDLE;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/cn/navclub/nes4j/app/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import cn.navclub.nes4j.app.config.NESConfig;
import cn.navclub.nes4j.app.util.JsonUtil;
import cn.navclub.nes4j.app.util.StrUtil;
import cn.navclub.nes4j.bin.log.Logger;
import cn.navclub.nes4j.bin.log.LoggerAdapter;
import javafx.application.Application;

import java.nio.file.Files;
import java.nio.file.Path;

public class Launcher {

private static final Logger logger = LoggerAdapter.logger(Launcher.class);
private static final String DEFAULT_CONFIG_PATH = "config/config.json";

public static void main(String[] args) throws Exception {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/cn/navclub/nes4j/app/util/StrUtil.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package cn.navclub.nes4j.app.util;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

@Slf4j
public class StrUtil {
/**
* 获取文件名称且移除后缀
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/cn/navclub/nes4j/app/view/GameHall.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.TimeZone;

/**
* Visible Game wall
Expand All @@ -44,12 +46,14 @@ public GameHall(Stage stage) {
this.gameWorld = new GameWorld();

Scene scene = new Scene(FXResource.loadFXML(this));

this.stage = stage;
this.stage.setWidth(1200);
this.stage.setHeight(900);
this.stage.setTitle("ines");
this.stage.setTitle("nes4j");
this.stage.setScene(scene);
this.stage.initStyle(StageStyle.UNDECORATED);
this.stage.getIcons().add(FXResource.loadImage("nes4j.png"));
this.stage.show();

this.loadAssort();
Expand Down Expand Up @@ -117,9 +121,21 @@ protected List<File> call() {
};
}

/**
* <p>
* Open current project open source address.If user location in China will visit <a href="gitee.com">gitee</a>,
* otherwise visit <a href="https://github.com">github</a>.</p>
*/
@FXML
public void github() {
INes.eventBus.publish(EventBusAddress.OPEN_URI, "https://github.com/GZYangKui/nes4j");
final String uri;
var tid = TimeZone.getDefault().getID();
if (tid.toLowerCase().contains("shanghai")) {
uri = "https://gitee.com/navigatorcode/nes4j";
} else {
uri = "https://github.com/GZYangKui/nes4j";
}
INes.eventBus.publish(EventBusAddress.OPEN_URI, uri);
}

@FXML
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
requires cn.navclub.nes4j.bin;
requires org.controlsfx.controls;

requires org.slf4j;
requires ch.qos.logback.core;
requires ch.qos.logback.classic;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "common.css";


.navbar *, .assort, .flow-pane .game-tray .label, .empty .label {
-fx-font-size: 1.4em;
-fx-text-fill: -nes4j-game-hall-text-fill;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<FlowPane styleClass="flow-pane" fx:id="flowPane"/>
</fx:define>
<left>
<VBox>
<VBox styleClass="left-box">
<HBox styleClass="x-box" NodeDragEvent.bind="" prefHeight="${navbar.height}">
<Circle radius="8" fill="#c18b16" onMouseClicked="#iconified"/>
<Circle radius="8" fill="#59c837"/>
Expand All @@ -29,11 +29,6 @@
<VBox styleClass="content">
<HBox fx:id="navbar" styleClass="navbar" NodeDragEvent.bind="">
<HBox styleClass="left-box">
<Button>
<graphic>
<Label styleClass="prefix,back"/>
</graphic>
</Button>
<SearchTextField/>
</HBox>
<HBox HBox.hgrow="ALWAYS" styleClass="right-box">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 0 additions & 35 deletions app/src/main/resources/logback.xml

This file was deleted.

17 changes: 0 additions & 17 deletions bin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,6 @@
</developer>
</developers>


<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand Down
6 changes: 0 additions & 6 deletions bin/src/main/java/cn/navclub/nes4j/bin/NES.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import cn.navclub.nes4j.bin.apu.APU;
import cn.navclub.nes4j.bin.apu.Player;
import cn.navclub.nes4j.bin.core.*;
import cn.navclub.nes4j.bin.core.impl.NRMapper;
import cn.navclub.nes4j.bin.core.impl.UXMapper;
import cn.navclub.nes4j.bin.debug.Debugger;
import cn.navclub.nes4j.bin.config.CPUInterrupt;
import cn.navclub.nes4j.bin.eventbus.EventBus;
Expand All @@ -15,15 +13,11 @@
import cn.navclub.nes4j.bin.ppu.PPU;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.LockSupport;

@Slf4j
@Getter
public class NES {
private final Bus bus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*
* @author <a href="https://github.com/GZYangKui">GZYangKui</a>
*/
@Slf4j
public class FrameCounter implements Component {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*
* @author <a href="https://github.com/GZYangKui">GZYangKui</a>
*/
@Slf4j
public enum Instruction {
/**
* More detail please visit:<a href="https://www.nesdev.org/obelisk-6502-guide/reference.html#ADC">ADC Document</a>
Expand Down
4 changes: 0 additions & 4 deletions bin/src/main/java/cn/navclub/nes4j/bin/core/Bus.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

import cn.navclub.nes4j.bin.NES;
import cn.navclub.nes4j.bin.apu.APU;
import cn.navclub.nes4j.bin.config.NMapper;
import cn.navclub.nes4j.bin.io.Cartridge;
import cn.navclub.nes4j.bin.io.JoyPad;
import cn.navclub.nes4j.bin.ppu.PPU;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import static cn.navclub.nes4j.bin.util.BinUtil.int8;
import static cn.navclub.nes4j.bin.util.BinUtil.uint8;

/**
* @author <a href="https://github.com/GZYangKui">GZYangKui</a>
*/
@Slf4j
public class Bus implements Component {
private static final int RPG_ROM = 0x8000;
private static final int RPG_ROM_END = 0xFFFF;
Expand Down
9 changes: 6 additions & 3 deletions bin/src/main/java/cn/navclub/nes4j/bin/core/CPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import cn.navclub.nes4j.bin.NES;
import cn.navclub.nes4j.bin.config.*;
import cn.navclub.nes4j.bin.core.register.CPUStatus;
import cn.navclub.nes4j.bin.log.Logger;
import cn.navclub.nes4j.bin.log.LoggerAdapter;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -16,8 +18,9 @@
*
* @author <a href="https://github.com/GZYangKui">GZYangKui</a>
*/
@Slf4j
public class CPU {
private final static Logger logger = LoggerAdapter.logger(CPU.class);

//Stack offset
public static final int STACK = 0x0100;
//Program counter reset offset
Expand Down Expand Up @@ -375,12 +378,12 @@ public int next() {
var mode = instruction6502.getAddressMode();
var instruction = instruction6502.getInstruction();

if (log.isDebugEnabled()) {
if (logger.isDebugEnabled()) {
var operand = "";
if (mode != AddressMode.Implied && mode != AddressMode.Accumulator && mode != AddressMode.Relative) {
operand = "0x" + Integer.toHexString(this.modeProvider.getAbsAddr(mode));
}
log.debug(
logger.debug(
"[0x{}] A:{} X:{} Y:{} S:{} {} {}",
Integer.toHexString(this.pc - 1),
Integer.toHexString(this.ra),
Expand Down
17 changes: 17 additions & 0 deletions bin/src/main/java/cn/navclub/nes4j/bin/log/Level.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cn.navclub.nes4j.bin.log;

/**
* Enum all log level
*
* @author <a href="https://github.com/GZYangKui">GZYangKui</a>
*/
public enum Level {
ALL,
TRACE,
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
OFF
}
42 changes: 42 additions & 0 deletions bin/src/main/java/cn/navclub/nes4j/bin/log/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cn.navclub.nes4j.bin.log;

public interface Logger {
/**
* Output a debug level message
*
* @param msg message content
* @param params message params
*/
void debug(String msg, Object... params);

/**
* Output a info level message
*
* @param msg message content
* @param params message params
*/
void info(String msg, Object... params);

/**
* Output a warning level message
*
* @param msg message content
* @param params message params
*/
void warning(String msg, Object... params);

/**
* Output a fatal level message
*
* @param msg message content
* @param throwable exception detail
*/
void fatal(String msg, Throwable throwable);

/**
* Whether debug is enable
*
* @return If debug is enable return {@code true} otherwise {@code false}
*/
boolean isDebugEnabled();
}
20 changes: 20 additions & 0 deletions bin/src/main/java/cn/navclub/nes4j/bin/log/LoggerAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cn.navclub.nes4j.bin.log;

import cn.navclub.nes4j.bin.log.impl.NLogger;

public class LoggerAdapter {
private static final Level level;

static {
var str = System.getProperty("nes4j.log.level");
if (str == null || str.trim().equals("")) {
level = Level.INFO;
} else {
level = Level.valueOf(str.toUpperCase());
}
}

public static Logger logger(Class<?> clazz) {
return new NLogger(clazz, level);
}
}
Loading

0 comments on commit bc51e53

Please sign in to comment.