OSDN Git Service

perf: changed log output source to logback
authorhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Sun, 14 Nov 2021 02:18:06 +0000 (11:18 +0900)
committerhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Sun, 14 Nov 2021 02:18:06 +0000 (11:18 +0900)
BREAKING CHANGE: after update, you will need to delete
"outputdebugsentences" settings in the settings.json. it might be a
fatal issue if you leave it.

generated/settings.json
resources/logback.xml [new file with mode: 0644]
src/com/ranfa/lib/AlbumTypeEstimate.java
src/com/ranfa/lib/EstimateAlbumTypeCycle.java
src/com/ranfa/lib/LimitedLog.java [deleted file]
src/com/ranfa/lib/Scraping.java
src/com/ranfa/lib/SettingJSONProperty.java
src/com/ranfa/lib/Settings.java
src/com/ranfa/main/DelesteRandomSelector.java

index 055eade..4a092ab 100644 (file)
@@ -4,6 +4,5 @@
   "windowWidth" : 640,
   "windowHeight" : 360,
   "songLimit" : 15,
-  "saveScoreLog" : false,
-  "outputDebugSentences" : true
+  "saveScoreLog" : false
 }
\ No newline at end of file
diff --git a/resources/logback.xml b/resources/logback.xml
new file mode 100644 (file)
index 0000000..8f310a5
--- /dev/null
@@ -0,0 +1,33 @@
+<configuration>
+
+  <!-- 標準出力用設定 -->
+  <appender name="BAR-STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>
+        %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+      </pattern>
+    </encoder>
+  </appender>
+
+  <!-- ファイル出力用設定 -->
+  <appender name="FOO-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+      <!-- 起動毎にログファイルを切り替える -->
+      <fileNamePattern>logs/log-%d{yyyy-MM-dd}.log</fileNamePattern>
+      <!-- 保持しておくログアーカイブファイルの最大数 -->
+      <maxHistory>90</maxHistory>
+    </rollingPolicy>
+    <encoder>
+      <pattern>%date %level [%thread] %logger{10} [%file : %line] %msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <!-- ルートロガー -->
+  <!-- DEBUG, INFO, WARN, ERROR レベルのログを出力 -->
+  <root level="DEBUG">
+    <!-- 全てのロガーのメッセージを定義した FOO-FILE アペンダーに出力 -->
+    <appender-ref ref="FOO-FILE"/>
+    <appender-ref ref="BAR-STDOUT"/>
+  </root>
+
+</configuration>
\ No newline at end of file
index 4df9aac..9acaa04 100644 (file)
@@ -8,10 +8,13 @@ import java.util.concurrent.ExecutionException;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.select.Elements;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class AlbumTypeEstimate {
 
        public final static String ALBUM_DATA_URI = "https://imascg-slstage-wiki.gamerch.com/%E6%A5%BD%E6%9B%B2%E8%A9%B3%E7%B4%B0%E4%B8%80%E8%A6%A7%EF%BC%88%E9%9B%A3%E6%98%93%E5%BA%A6%E5%88%A5%EF%BC%89";
+       private static Logger logger = LoggerFactory.getLogger(AlbumTypeEstimate.class);
 
        //アルバム種類の定義
        public enum ALBUM_TYPE {
@@ -49,7 +52,7 @@ public class AlbumTypeEstimate {
                } catch (IOException | InterruptedException | ExecutionException e) {
                        e.printStackTrace();
                }
-               LimitedLog.println(AlbumTypeEstimate.class + ":[INFO]: " + "Album type fetched in " + (System.currentTimeMillis() - time) + "ms");
+               logger.info("Album type fetched in " + (System.currentTimeMillis() - time) + "ms");
                return res;
        }
 
index b5755b2..8671336 100644 (file)
@@ -16,6 +16,9 @@ import java.util.Date;
 
 import javax.swing.JOptionPane;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
@@ -25,6 +28,7 @@ public class EstimateAlbumTypeCycle {
        private final static String CYCLEPATH = "generated/albumCycle.json";
        private final static String DATEFORMAT = "YYYY/MM/dd";
        private final static SimpleDateFormat FORMAT = new SimpleDateFormat(DATEFORMAT);
+       private static Logger logger = LoggerFactory.getLogger(EstimateAlbumTypeCycle.class);
 
        public final static String ALBUM_A = "ALBUM A";
        public final static String ALBUM_B = "ALBUM B";
@@ -33,11 +37,11 @@ public class EstimateAlbumTypeCycle {
        public static void Initialization() {
                if(Files.exists(Paths.get(CYCLEPATH)))
                        return;
-               LimitedLog.println(EstimateAlbumTypeCycle.class + ":[INFO]: " + "Cycle definition file does not exist.Trying to ask you...");
+               logger.info("Cycle definition file does not exist.Trying to ask you...");
                AlbumCycleDefinitionProperty property = new AlbumCycleDefinitionProperty();
                String inputType = JOptionPane.showInputDialog("現在のMASTER+のALBUMを入力してください。(A,B,C)");
                if(!(inputType.equals("A") || inputType.equals("B") || inputType.equals("C"))) {
-                       LimitedLog.println(EstimateAlbumTypeCycle.class + ":[FATAL]; " + "inputType has invaild.Canceling initiate...");
+                       logger.error("inputType has invaild.Canceling initiate...");
                        return;
                }
                String inputDaysLeft = JOptionPane.showInputDialog("MASTER+のALBUM切り替えまであと何日ですか?\n(残り時間が表示されている場合は0を入力してください)");
@@ -93,7 +97,7 @@ public class EstimateAlbumTypeCycle {
                        delta = delta - property.getDaysLeft();
                        if(delta > Integer.MAX_VALUE) {
                                JOptionPane.showMessageDialog(null, "ALBUM周期の推定に失敗しました。暫定的な措置として前回起動時のALBUM種類を表示します。\n(内部変数エラー:delta has the value that is more than Integer.MAX_VALUE.)");
-                               LimitedLog.println(EstimateAlbumTypeCycle.class + ":[FATAL]; " + "Valuable was overflowed.");
+                               logger.error("Valuable was overflowed.");
                        }
                        String res = cycling(property.getType(), (int)delta);
                        return res;
diff --git a/src/com/ranfa/lib/LimitedLog.java b/src/com/ranfa/lib/LimitedLog.java
deleted file mode 100644 (file)
index 84b95f7..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.ranfa.lib;
-
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-
-public class LimitedLog {
-
-       private final static String STRING_DATE_FORMAT = "YYYY-MM-dd HH-mm-ss-SSS: ";
-       private static SimpleDateFormat format = new SimpleDateFormat(STRING_DATE_FORMAT);
-
-       public static void print(String s) {
-               Calendar calendar = Calendar.getInstance();
-               if(!Settings.outputDebugSentences()) {
-                       return;
-               } else {
-                       System.out.print(format.format(calendar.getTime()) + s);
-                       return;
-               }
-       }
-
-       public static void println(String s) {
-               Calendar calendar = Calendar.getInstance();
-               if(!Settings.outputDebugSentences()) {
-                       return;
-               }
-               System.out.println(format.format(calendar.getTime()) + s);
-       }
-
-       public static void println() {
-               // TODO 自動生成されたメソッド・スタブ
-               if(!Settings.outputDebugSentences()) {
-                       return;
-               }
-               System.out.println();
-       }
-}
index 386b732..219e912 100644 (file)
@@ -17,6 +17,8 @@ import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.select.Elements;
 import org.junit.internal.ArrayComparisonFailure;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -27,6 +29,7 @@ public class Scraping {
 
        private final static String URI = "https://imascg-slstage-wiki.gamerch.com/%E6%A5%BD%E6%9B%B2%E8%A9%B3%E7%B4%B0%E4%B8%80%E8%A6%A7";
        private final static String DBPATH = "generated/database.json";
+       private static Logger logger = LoggerFactory.getLogger(Scraping.class);
        public final static String NONSELECTED = "指定なし";
        public final static String ALL = "全タイプ";
        public final static String CUTE = "キュート";
@@ -109,7 +112,7 @@ public class Scraping {
                } catch (IOException | InterruptedException | ExecutionException e) {
                        e.printStackTrace();
                }
-               LimitedLog.println(Scraping.class + ":[INFO]: scraping compeleted in " + (System.currentTimeMillis() - time)+ "ms");
+               logger.info("scraping compeleted in " + (System.currentTimeMillis() - time)+ "ms");
                return res;
        }
 
@@ -216,7 +219,7 @@ public class Scraping {
                }
                ArrayList<Song> res = new ArrayList<Song>();
                res.addAll(property.getList());
-               LimitedLog.println(Scraping.class + ":[INFO]: JSON reading compeleted in " + (System.currentTimeMillis() - time) + "ms");
+               logger.info("JSON reading compeleted in " + (System.currentTimeMillis() - time) + "ms");
                return res;
        }
 
index a4cf539..e7880cf 100644 (file)
@@ -8,7 +8,6 @@ public class SettingJSONProperty {
        private int windowHeight;
        private int songLimit;
        private boolean saveScoreLog;
-       private boolean outputDebugSentences;
 
 
        public boolean isCheckVersion() {
@@ -47,11 +46,5 @@ public class SettingJSONProperty {
        public void setSaveScoreLog(boolean saveScoreLog) {
                this.saveScoreLog = saveScoreLog;
        }
-       public boolean isOutputDebugSentences() {
-               return outputDebugSentences;
-       }
-       public void setOutputDebugSentences(boolean outputDebugSentences) {
-               this.outputDebugSentences = outputDebugSentences;
-       }
 
 }
index 3749d27..9c1176d 100644 (file)
@@ -19,8 +19,7 @@ import com.fasterxml.jackson.databind.ObjectWriter;
  * ・ウィンドウサイズ (windowWidth), (windowHeight)
  * ・デフォルトの曲指定上限数 (songsLimit)
  * ・スコアログの保存 (saveScoreLog)
- * ・標準出力へデバッグ用簡易ログを流すかどうか (outputDebugSentences)
- * の6つ(括弧内はフィールド名)
+ * の5つ(括弧内はフィールド名)
  * 今後、設定可能事項は増える可能性あり
  * @author hizum
  * @since v1.0.0
@@ -108,18 +107,6 @@ public class Settings {
                return res;
        }
 
-       public static boolean outputDebugSentences() {
-               boolean res = false;
-               ObjectMapper mapper = new ObjectMapper();
-               try {
-                       JsonNode node = mapper.readTree(new File(FILEPATH));
-                       res = node.get("outputDebugSentences").asBoolean();
-               } catch (IOException e) {
-                       e.printStackTrace();
-               }
-               return res;
-       }
-
        public static boolean writeDownJSON() {
                boolean res = true;
                SettingJSONProperty property = new SettingJSONProperty();
@@ -129,7 +116,6 @@ public class Settings {
                property.setWindowHeight(360);
                property.setSongLimit(3);
                property.setSaveScoreLog(false);
-               property.setOutputDebugSentences(false);
                ObjectWriter writer = new ObjectMapper().writer(new DefaultPrettyPrinter());
                try {
                        writer.writeValue(Paths.get(FILEPATH).toFile(), property);
index 6591068..8bc1d84 100644 (file)
@@ -29,13 +29,15 @@ import javax.swing.JSpinner;
 import javax.swing.JTextArea;
 import javax.swing.border.EmptyBorder;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.jgoodies.forms.layout.ColumnSpec;
 import com.jgoodies.forms.layout.FormLayout;
 import com.jgoodies.forms.layout.FormSpecs;
 import com.jgoodies.forms.layout.RowSpec;
 import com.ranfa.lib.CheckVersion;
 import com.ranfa.lib.EstimateAlbumTypeCycle;
-import com.ranfa.lib.LimitedLog;
 import com.ranfa.lib.Scraping;
 import com.ranfa.lib.SettingJSONProperty;
 import com.ranfa.lib.Settings;
@@ -75,6 +77,7 @@ public class DelesteRandomSelector extends JFrame {
        private CompletableFuture<Void> softwareUpdateFuture = null;
        private CompletableFuture<Void> albumTypeEstimateFuture = null;
        private String albumType = "計算中";
+       private Logger logger = LoggerFactory.getLogger(DelesteRandomSelector.class);
 
        /**
         * Launch the application.
@@ -116,22 +119,20 @@ public class DelesteRandomSelector extends JFrame {
                        JOptionPane.showMessageDialog(this, "Exception:NullPointerException\nCannot Keep up! Please re-download this Application!");
                        throw new NullPointerException("FATAL: cannot continue!");
                }
-               LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Loading Settings...");
+               logger.debug("Loading settings...");
                property.setCheckLibraryUpdates(Settings.needToCheckLibraryUpdates());
                property.setCheckVersion(Settings.needToCheckVersion());
                property.setWindowWidth(Settings.getWindowWidth());
                property.setWindowHeight(Settings.getWindowHeight());
                property.setSongLimit(Settings.getSongsLimit());
                property.setSaveScoreLog(Settings.saveScoreLog());
-               property.setOutputDebugSentences(Settings.outputDebugSentences());
-               LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Loading Settings done."
-                               + "\nVersion Check: " + property.isCheckVersion()
-                               + "\nLibrary Update Check: " + property.isCheckLibraryUpdates()
-                               + "\nWindow Width: " + property.getWindowWidth()
-                               + "\nWindow Height: " + property.getWindowHeight()
-                               + "\nSong Limit: " + property.getSongLimit()
-                               + "\nSaveScoreLog: " + property.isSaveScoreLog()
-                               + "\nOutputDebugSentences: " + property.isOutputDebugSentences());
+               logger.debug("Load settings done.");
+               logger.debug("Version check: " + property.isCheckVersion());
+               logger.debug("Library update check: " + property.isCheckLibraryUpdates());
+               logger.debug("Window Width: " + property.getWindowWidth());
+               logger.debug("Window Height: " + property.getWindowHeight());
+               logger.debug("Song Limit: " + property.getSongLimit());
+               logger.debug("SaveScoreLog: " + property.isSaveScoreLog());
                EstimateAlbumTypeCycle.Initialization();
                if(Files.exists(Paths.get("generated/albumCycle.json"))) {
                        albumType = EstimateAlbumTypeCycle.getCurrentCycle();
@@ -140,15 +141,15 @@ public class DelesteRandomSelector extends JFrame {
                        softwareUpdateFuture = CompletableFuture.runAsync(() -> CheckVersion.needToBeUpdated(), es);
                }
                BiConsumer<ArrayList<Song>, ArrayList<Song>> updateConsumer = (list1, list2) -> {
-                       LimitedLog.println(this.getClass() + ":[INFO]: " + "Checking database updates...");
+                       logger.info("Checking database updates...");
                        if(list1.size() > list2.size()) {
                                long time = System.currentTimeMillis();
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + (list1.size() - list2.size()) + " Update detected.");
+                               logger.info((list1.size() - list2.size()) + " Update detected.");
                                Scraping.writeToJson(list1);
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Update completed in " + (System.currentTimeMillis() - time) + "ms");
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Updated database size: " + list1.size());
+                               logger.info("Update completed in " + (System.currentTimeMillis() - time) + "ms");
+                               logger.info("Updated database size: " + list1.size());
                        } else {
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "database is up-to-date.");
+                               logger.info("database is up-to-date.");
                        }
                };
                Runnable setEnabled = () -> {
@@ -161,13 +162,13 @@ public class DelesteRandomSelector extends JFrame {
                        btnImport.setEnabled(true);
                        btnImport.setText("<html><body>楽曲<br>絞り込み</body></html>");
                };
-               getWholeDataFuture.thenAcceptAsync(list -> LimitedLog.println(this.getClass() + ":[INFO]: Scraping data size:" + list.size()), es);
-               getFromJsonFuture.thenAcceptAsync(list -> LimitedLog.println(this.getClass() + ":[INFO]: Currently database size:" + list.size()), es);
+               getWholeDataFuture.thenAcceptAsync(list -> logger.info("Scraping data size:" + list.size()), es);
+               getFromJsonFuture.thenAcceptAsync(list -> logger.info("Currently database size:" + list.size()), es);
                if(property.isCheckLibraryUpdates()) {
                        CompletableFuture<Void> updatedFuture = getWholeDataFuture.thenAcceptBothAsync(getFromJsonFuture, updateConsumer, es);
                        updatedFuture.thenRunAsync(setEnabled, es);
                }
-               LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Version:" + CheckVersion.getVersion());
+               logger.debug("Version:" + CheckVersion.getVersion());
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setBounds(100, 100, property.getWindowWidth(), property.getWindowHeight());
                // setBounds(100, 100, 640, 360);
@@ -284,7 +285,7 @@ public class DelesteRandomSelector extends JFrame {
                                        if(!selectedSongsList.isEmpty())
                                        selectedSongsList.clear();
                                selectedSongsList.addAll((comboDifficultySelect.getSelectedItem().equals(Scraping.MASTERPLUS) || comboDifficultySelect.getSelectedItem().equals(Scraping.LEGACYMASTERPLUS)) ? specificTypeList : specificAttributeList);
-                               LimitedLog.println(this.getClass() + ":[INFO]: " +"Songs are selected.We are Ready to go.");
+                               logger.info("Songs are selected.We are Ready to go.");
                                JOptionPane.showMessageDialog(null, "絞り込み完了!「開始」をクリックすることで選曲できます!");
                        }
                });
@@ -306,7 +307,7 @@ public class DelesteRandomSelector extends JFrame {
                                paneString = paneString + "この" + property.getSongLimit() + "曲をプレイしましょう!!!";
                                textArea.setText(paneString);
                                integratorBool = true;
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "show up completed.");
+                               logger.info("show up completed.");
                        }
                });
                btnStart.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 13));
@@ -316,16 +317,12 @@ public class DelesteRandomSelector extends JFrame {
                                btnTwitterIntegration.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 11));
                                btnTwitterIntegration.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
-                                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Twitter Integration requested.Verify permission status.");
                                                boolean authorizationStatus = TwitterIntegration.authorization();
-                                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Permission Verifying completed.\nStatus: " + authorizationStatus);
-                                               LimitedLog.print(this.getClass() + ":[INFO]: " + "Construction status message...");
                                                String updatedStatus = "デレステ課題曲セレクターで\n";
                                                int lengthLimit = updatedStatus.length();
                                                boolean isBroken = false;
                                                if(!integratorBool) {
                                                        JOptionPane.showMessageDialog(null, "ちひろ「まだプレイを始めていないみたいですね」");
-                                                       LimitedLog.println();
                                                        return;
                                                }
                                                for(int i = 0; i < integratorArray.length; i++) {
@@ -341,28 +338,28 @@ public class DelesteRandomSelector extends JFrame {
                                                } else {
                                                        updatedStatus = updatedStatus + "をプレイしました!\n#DelesteRandomSelector #デレステ ";
                                                }
-                                               LimitedLog.println("completed.\n" + updatedStatus);
+                                               logger.info("status message constructed.");
                                                lengthLimit = updatedStatus.length();
                                                if(authorizationStatus) {
                                                        int option = JOptionPane.showConfirmDialog(null, "Twitterへ以下の内容を投稿します。よろしいですか?\n\n" + updatedStatus + "\n\n文字数:" + lengthLimit);
-                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "User selected " + option);
+                                                       logger.info("user seletced: " + option);
                                                        switch(option) {
                                                                case JOptionPane.OK_OPTION:
                                                                        TwitterIntegration.PostTwitter(updatedStatus);
-                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "Success to update the status.");
+                                                                       logger.info("Success to update the status.");
                                                                        JOptionPane.showMessageDialog(null, "投稿が完了しました。");
                                                                        break;
                                                                case JOptionPane.NO_OPTION:
-                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "There is no will to post.");
+                                                                       logger.info("There is no will to post.");
                                                                        break;
                                                                case JOptionPane.CANCEL_OPTION:
-                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "The Operation was canceled by user.");
+                                                                       logger.info("The Operation was canceled by user.");
                                                                        break;
                                                                default:
                                                                        break;
                                                        }
                                                } else {
-                                                       LimitedLog.println(this.getClass() + ":[WARN]: " + "seems to reject the permission.it should need try again.");
+                                                       logger.info("seems to reject the permission.it should need try again.");
                                                }
                                        }
                                });
@@ -372,7 +369,7 @@ public class DelesteRandomSelector extends JFrame {
                                                                btnExit.addActionListener(new ActionListener() {
                                                                        public void actionPerformed(ActionEvent e) {
                                                                                if(softwareUpdateFuture.isDone() || albumTypeEstimateFuture.isDone()) {
-                                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " +"Requested Exit by Button");
+                                                                                       logger.info("Requested Exit by Button");
                                                                                        System.exit(0);
                                                                                } else {
                                                                                        JOptionPane.showMessageDialog(null, "内部更新処理が完了していません。少し待ってからやり直してください。");