> For the complete documentation index, see [llms.txt](https://help.diarkis.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.diarkis.io/diarkis-client/diarkis-module/log-output.md).

# Diarkis Module のロギング・システム

## 概要

本ページでは Diarkis Module のロギング・システムについて説明します。

Diarkis Module では Diarkis ランタイム・ライブラリおよび Diarkis Module の動作状況をログに出力しています。出力されたログは標準出力やファイル出力など様々な方法で確認することができます。想定したように動作しない場合や Diarkis ランタイムの動作状況を確認したい場合はまず初めにログ・ファイルを内容を確認することをお勧めします。

## ロギング・システムの設定

Diarkis Module のロギング・システムの設定は `DiarkisInterfaceBase::DiarkisInit()` に渡す引数でコントロールします。ログ・ディレクトリ名、出力方法、ログを出力するかどうか等を設定することができます。

## Diarkis Module のログ出力方法

Diarkis Module では以下の出力方法をサポートしています。

| enum                      | 説明                                                                            |
| ------------------------- | ----------------------------------------------------------------------------- |
| DEBUG\_OUT                | デバッガーへログが出力可能であればデバッガーへ、出力できなければ標準出力にログを出力します                                 |
| FILE\_OUT                 | ファイルへログを出力します。`GetLogDirectoryPath()` で取得したパスに `diarkis-log.log` という名前で出力されます |
| FILE\_OUT\_SPECIFIC\_PATH | 指定したパスへログ・ファイルを出力します                                                          |
| CONSOLE\_OUT              | 標準出力にログを出力します                                                                 |
| DEBUG\_AND\_FILE\_OUT     | DEBUG\_OUT と FILE\_OUT を合わせた挙動になります                                           |
| CUSTOM                    | ユーザーが定義したカスタム・ロガーへログを出力します                                                    |

## ログ出力レベル

Diarkis Module のロギング・システムではログに出力する内容の詳細度を調整するログ出力レベルを設定することができます。`diarkis-module\Client\Private\logging\LoggerFactory.cpp` で実装している `LoggerFactory` のコンストラクターにデフォルトのログ出力レベルが記載されているため、これを変更することで変えることができます。また、`LoggerFactory::SetSeverity()` を使用してアプリ実行中に動的に変更することも可能です。

ログの出力レベルには以下の設定があります。下の設定ほどログの詳細度がまします。また、詳細度が高いログレベルは下位のログ・レベルを常に内包します。 Verbose や Trace は Diarkis ランタイムの動作速度に影響したり、ログ・ファイルが巨大になる可能性がありますので使用する際はご注意ください。

| enum    | 説明                                     |
| ------- | -------------------------------------- |
| None    | ログを出力しません                              |
| Fatal   | 致命的なエラーのログを出力します                       |
| Error   | 一般的なエラーも含めてログを出力します                    |
| Warning | 警告を含めたログを出力します                         |
| Info    | 付加情報を含めたログを出力します                       |
| Debug   | デバッグ情報を含めたログを出力します                     |
| Verbose | 詳細なデバッグ情報を含めたログを出力します                  |
| Trace   | ランタイムの動作や送受信したペイロードなどを可能な限り詳細にログに出力します |

## カテゴリ毎に確認できるログの内容

クライアント・ライブラリのロギング・システムでは、カテゴリ毎にログ・レベルを変更できる仕組みが用意されております。デバック時に確認されたい内容に合わせて、必要なカテゴリのログ・レベルを変更してご確認ください。

<table><thead><tr><th width="233">代表的なカテゴリ</th><th>デバック時に確認できる内容</th></tr></thead><tbody><tr><td>UDP</td><td>UDP サーバーとの Connect, Disconnect の確認。意図しない切断時。パケットロスが発生している時の ack, eack を確認したい時</td></tr><tr><td>RUDP</td><td>パケットロスが発生している時に、RUDP パケット、シーケンス番号の処理状況を確認したい時</td></tr><tr><td>Socket</td><td>意図せずに切断した際など、Socket 回りの処理を確認したい時</td></tr><tr><td>P2P</td><td>P2P 通信時に、ホールパンチやパケット通信周りで意図しない問題があり確認したい時</td></tr><tr><td>Runtime</td><td>アプリケーションを実装する際に、パケットの送受信やサーバーからの通知や応答が来ない時に確認したい時</td></tr><tr><td>Room など各モジュールのカテゴリ</td><td>各モジュールを実装される際に、パケットの送受信やサーバーからの通知や応答が来ない時に確認したい時</td></tr></tbody></table>

## カスタム・ロガーの実装

カスタム・ロガーを使用すると、ロガーの動作をユーザーが自由にカスタマイズすることができます。\
`ILoggerBackend` を継承して `ILoggerBackend::Log()` をオーバーライドすることにより Diarkis ランタイムおよび Diarkis Module のログ出力処理をハンドリングすることができます。\
以下がサンプル実装です。

```
// アプリケーション・カスタムのログ出力サンプル実装
class AppCustomLoggerBackend : public ILoggerBackend
{
    public:
        AppCustomLoggerBackend() {}
        virtual ~AppCustomLoggerBackend() {}

        virtual Result Log(const Diarkis::StdString& message, bool includeNewLine) override
        {
            // ログ・テキストが message として渡されるため、アプリ固有のログ出力を行う
            // 排他制御は行われているため複数スレッドから呼び出しても問題ない
            DiarkisUtils::Print("%s", message.c_str());
            return Diarkis::Results::SUCCESS;
        }
};

...
// カスタム・ロガーを初期化時に指定する疑似コード
AppCustomLoggerBackend customLogger;

DiarkisInterface::DiarkisInit(uid, LogOutType::CUSTOM, bOutLog, &customLogger);


```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.diarkis.io/diarkis-client/diarkis-module/log-output.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
