iOS ロギングをカスタマイズする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
iOS のロギングは IOSLogHandler.java によって処理されます。
これは java.util.logging.Handler
をオーバーライドします。logging.properties
リソースを追加することで、デフォルトとして設定できます。
LogManager で確認できます。
プログラムでロギング ハンドラを変更する
プログラムでロギング ハンドラを追加するには、Java で変更する場合と同じコードを使用します。
LogManager.getLogger("").addHandler(myHandler);
既存のハンドラを実行しない場合は、まず以下を使用してハンドラを削除します。
Logger logger = LogManager.getLogger("");
for (Handler h : logger.getHandlers()) {
logger.removeHandler(h);
}
プロパティ ファイルを使用したロギング ハンドラの変更
logging.properties ファイルを使用してデフォルトのロギング ハンドラを変更するには、そのハンドラを指定する必要があります。
(Java アプリケーションの場合と同じ):
handlers=mycompany.mylogger.MyIOSLogHandler
java.util.logging.ConsoleHandler.level=ALL
このファイルには、読み込み時にその名前が使用されている限り、任意の名前を付けることができます。
次に、プロジェクトに logging.properties ファイルを iOS リソースとして追加します。
Java アプリケーションとは異なり、J2ObjC アプリケーションではプロパティ ファイルを明示的に読み込む必要があります。
static {
// Fetch a logger in case the following leaves logging in a bad state, such
// as not adding the logging.properties resource or using a different name.
Logger log = Logger.getLogger("configLogger");
try {
InputStream loggingProperties = SomeClass.class.getResourceAsStream("logging.properties");
LogManager.getLogManager().readConfiguration(loggingProperties);
} catch (IOException exception) {
log.log(Level.SEVERE, "Error in loading configuration", exception);
}
}
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-25 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-25 UTC。"],[[["iOS logging in J2ObjC applications uses a custom `IOSLogHandler` that overrides the standard Java logging handler."],["You can modify the logging behavior either programmatically by adding or removing handlers or by using a `logging.properties` file."],["To use a `logging.properties` file, you need to add it as an iOS resource and explicitly load it within your application code."],["When loading a custom `logging.properties` file, make sure to handle potential errors, such as missing files or incorrect configurations."]]],["iOS logging uses `IOSLogHandler.java`, which can be set as the default via a `logging.properties` resource. Programmatically, handlers are added using `LogManager.getLogger(\"\").addHandler(myHandler)`. Existing handlers can be removed with `logger.removeHandler(h)`. With a property file, specify the handler (e.g., `handlers=mycompany.mylogger.MyIOSLogHandler`) and add it as an iOS resource. The property file must be explicitly loaded in a J2ObjC app using `LogManager.getLogManager().readConfiguration(loggingProperties)`.\n"]]