Comments (6)
基本は公式ページに説明されてある。
https://wiki.eclipse.org/Paho/Log_and_Debug_in_the_Java_client
from mqttv5-client.
Javaの標準パッケージであるjava.util.logging
を使用している。仕様はJSR47やJavaDocを見るように書いてある。
JSRは"Java Specification Request"でJavaの仕様のことらしい。RFCのようなもの?
from mqttv5-client.
Loggerの設定方法として、-D
オプションで設定ファイルのパスを渡す方法がある。
-Djava.util.logging.config.file=<パス>/<設定ファイル>
をJava実行時の引数で指定することで設定が反映される。
(-Dkey=val
オプションはJavaのシステムプロパティになるようです(参考。System.getProperty(ket)
で取得可能)
設定ファイルは以下のような記述になる。
# Properties file which configures the operation of the JDK logging facility.
#
# The configuration in this file is the suggesgted configuration
# for collecting trace for helping debug problems related to the
# Paho MQTT client. It configures trace to be continuosly collected
# in memory with minimal impact on performance.
#
# When the push trigger (by default a Severe level message) or a
# specific request is made to "push" the in memory trace then it
# is "pushed" to the configured target handler. By default
# this is the standard java.util.logging.FileHandler. The Paho Debug
# class can be used to push the memory trace to its target
#
# To enable trace either:
# - use this properties file as is and set the logging facility up
# to use it by configuring the util logging system property e.g.
#
# >java -Djava.util.logging.config.file=<location>\jsr47min.properties
#
# - This contents of this file can also be merged with another
# java.util.logging config file to ensure provide wider logging
# and trace including Paho trace
# Global logging properties.
# ------------------------------------------
# The set of handlers to be loaded upon startup.
# Comma-separated list of class names.
# - Root handlers are not enabled by default - just handlers on the Paho packages.
#handlers=java.util.logging.MemoryHandler,java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# Default global logging level.
# Loggers and Handlers may override this level
#.level=INFO
# Loggers
# ------------------------------------------
# A memoryhandler is attached to the paho packages
# and the level specified to collected all trace related
# to paho packages. This will override any root/global
# level handlers if set.
org.eclipse.paho.mqttv5.client.handlers=java.util.logging.MemoryHandler
org.eclipse.paho.mqttv5.client.level=ALL
# It is possible to set more granular trace on a per class basis e.g.
#org.eclipse.paho.mqttv5.client.internal.ClientComms.level=ALL
# Handlers
# -----------------------------------------
# Note: the target handler that is associated with the MemoryHandler is not a root handler
# and hence not returned when getting the handlers from root. It appears accessing
# target handler programatically is not possible as target is a private variable in
# class MemoryHandler
java.util.logging.MemoryHandler.level=ALL
java.util.logging.MemoryHandler.size=10000
java.util.logging.MemoryHandler.push=ALL
#java.util.logging.MemoryHandler.target=java.util.logging.FileHandler
java.util.logging.MemoryHandler.target=java.util.logging.ConsoleHandler
# --- FileHandler ---
# Override of global logging level
java.util.logging.FileHandler.level=INFO
# Naming style for the output file:
# (The output file is placed in the directory
# defined by the "user.home" System property.)
# See java.util.logging for more options
java.util.logging.FileHandler.pattern=%h/ibm/paho/trace/paho%u.log
# Limiting size of output file in bytes:
java.util.logging.FileHandler.limit=200000
# Number of output files to cycle through, by appending an
# integer to the base file name:
java.util.logging.FileHandler.count=3
# Style of output (Simple or XML):
java.util.logging.FileHandler.formatter=org.eclipse.paho.mqttv5.client.logging.SimpleLogFormatter
# --- ConsoleHandler ---
# Override of global logging level
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.formatter=org.eclipse.paho.mqttv5.client.logging.SimpleLogFormatter
from mqttv5-client.
実行時の表示はこんな感じ。左から順に
Level Data & Time Class Method Thread clientID Message
が表示されてる。
スレッド別のログが表示されているため、cut
とgrep
を利用することで特定の処理がどのスレッドのどのクラスで実行されているかがトレースできる。
from mqttv5-client.
java.util.logging
はパッケージ毎にロガーの設定を変更することができる.
# グローバルな設定
handlers=java.util.logging.MemoryHandler
.level=FINE
# パッケージ毎の設定
org.eclipse.paho.mqttv5.client.handlers=java.util.logging.MemoryHandler
org.eclipse.paho.mqttv5.client.level=INFO
この設定でorg.eclipse.paho.mqttv5.client.handlers
のパッケージのみレベルがINFOになり,他のパッケージはFINEになる.
from mqttv5-client.
このパッケージではロギングメッセージをorg.eclipse.paho.mqttv5.client.internal.nls.logcat
に格納している.
これはメッセージのローカライズに利用する手法らしい.
ResouceBundle
でロギングメッセージを格納したプロパティファイルを読み込むことでメッセージを柔軟に変更することができる.
例えば,クラスパス上に以下のプロパティファイルを作成する.(プロパティファイルの仕様:BaseName[_Language][_Country][_Variant].properties)
MyMessages_en_US.properties
greeting=Hello
MyMessages_ja_JP.properties
greeting=こんにちは
以下のようなJavaファイルを作成することでログメッセージを切り替えることができる.
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Logger;
public class LocaleChangeExample {
public static void main(String[] args) {
// 英語のResourceBundleを使用するLogger
ResourceBundle bundleEN = ResourceBundle.getBundle("MyMessages", Locale.US);
Logger loggerEN = Logger.getLogger("TestLogger", bundleEN.getBaseBundleName());
// ログ出力(英語)
loggerEN.info(loggerEN.getResourceBundle().getString("greeting")); // Output: Hello
// 日本語のResourceBundleを使用するLogger
ResourceBundle bundleJA = ResourceBundle.getBundle("MyMessages", Locale.JAPAN);
Logger loggerJA = Logger.getLogger("TestLogger", bundleJA.getBaseBundleName());
// ログ出力(日本語)
loggerJA.info(loggerJA.getResourceBundle().getString("greeting")); // Output: こんにちは
}
}
from mqttv5-client.
Related Issues (10)
- PINGREQの送信タイミングを拡張する HOT 15
- パケットフォーマットの拡張 HOT 2
- PingSenderの拡張実装 HOT 2
- 送信データ取得の実装 HOT 3
- コンテナ環境での評価クライアントの実装
- PINGREQで送信できるデータを拡張する HOT 4
- 拡張したPINGREQで分散配信を制御できるかを検証する HOT 1
- 受信したメッセージのキューイングに関する調査 HOT 5
- [クライアント] 拡張PINGREQによる動的負荷分散の実装と評価 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqttv5-client.