> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/ja/additional-features/collect-logs-with-secure-logger.md). Agents can also search and read this documentation through its [MCP server](https://docs.payments.thalescloud.io/~gitbook/mcp).

# セキュアロガーでログを収集する

## 概要

セキュアロガーはNFC Wallet SDKの実行ログを収集し、アプリケーションのサンドボックス内に安全に保存します。

デジタルウォレットアプリケーションからログファイルを取得し、トラブルシューティングのためにThalesと共有できます。

## SDKの統合

### ログレベルを設定する

セキュアロガーはデフォルトで有効になっており、ログレベルは `warn`.

<table><thead><tr><th width="109">ログレベル</th><th>説明</th></tr></thead><tbody><tr><td><code>debug</code></td><td>トラブルシューティングとデバッグに役立つ詳細情報を記録します。</td></tr><tr><td><code>info</code></td><td>APIの開始点／終了点や戻り値など、通常のメッセージを記録します。</td></tr><tr><td><code>warn</code></td><td>通常の実行中に発生する警告や、重要なフローの問題を記録します。</td></tr><tr><td><code>error</code></td><td>フローの正常な完了を妨げるエラーを記録します。</td></tr><tr><td><code>fatal</code></td><td>直ちに対処が必要な実行時エラーを記録します。</td></tr><tr><td><code>off</code></td><td>ログ記録を無効にします。</td></tr></tbody></table>

### セキュアロガーのインスタンスを取得する

SDKからセキュアロガーのインスタンスを取得します。

```swift
// TSHPay SDKからsecurelogオブジェクトを取得
let securelog = TSHPay.secureLog
```

本番環境では、通常時は `warn` に設定してください。

問題を再現する場合は、エンドユーザーに、より詳細なログレベルを有効にしてもらいます。その後、問題を再現し、ログファイルを共有してください。

### セキュアロガーを無効にする

セキュアロガーを無効にするには、次のようにします。

```swift
// レベルをoffに設定すると、ログ記録が無効になります。MPAでは、別のレベル（例: debug）を選択して有効にできます。
securelog.setLevel(.off)
```

### ログファイルを取得する

ログファイルを取得するには、次のようにします。

```swift
// ファイルのリストを返す
let files = securelog.files()
```

### ログファイルを削除する

ログファイルを削除するには、次のようにします。

```swift
// ファイルを削除
securelog.deleteFiles()
```

### ログファイルを共有する（例）

この例では、 `UIActivityViewController`.

を使ってログを共有します。デジタルウォレットアプリケーションから、ログをファイルサーバーにアップロードすることもできます。

承認済みのほかの方法でログを送信することもできます。

{% code expandable="true" %}

```swift
// ログを共有
    func archieveLogsURL(_ onComplete: @escaping (URL?) -> ()) {
        var error: NSError?
        guard let file = TSHPay.secureLog.files().first?.absoluteURL.deletingLastPathComponent(),
            let fileURL = URL(string: "file://\(file.absoluteString)") else {
            onComplete(nil)
            return
        }
        
        NSFileCoordinator().coordinate(
            readingItemAt: fileURL,
            options: [.forUploading],
            error: &error
        ) { zipUrl in
            do {
                let tmpUrl = try FileManager.default
                    .url(
                        for: .itemReplacementDirectory,
                        in: .userDomainMask,
                        appropriateFor: zipUrl,
                        create: true
                    )
                    .appendingPathComponent("archive.zip")
                
                try FileManager.default.moveItem(at: zipUrl, to: tmpUrl)
                onComplete(tmpUrl)
            } catch {
                onComplete(nil)
            }
        }
    }
```

{% endcode %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/ja/additional-features/collect-logs-with-secure-logger.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
