> 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/additional-features/collect-logs-with-secure-logger.md).

# Collect logs with secure logger

## Overview

The secure logger collects NFC Wallet SDK execution logs. It stores them securely in the application sandbox.

Your digital wallet application can retrieve log files and share them with Thales for troubleshooting.

## SDK Integration

### Set the log level

Secure logger is enabled by default with the log level set to `warn`.

<table><thead><tr><th width="109">Log level</th><th>Description</th></tr></thead><tbody><tr><td><code>debug</code></td><td>Log detailed information for troubleshooting and debugging.</td></tr><tr><td><code>info</code></td><td>Log routine messages, such as API entry/exit points and returned values.</td></tr><tr><td><code>warn</code></td><td>Log warnings and critical flow issues during normal execution.</td></tr><tr><td><code>error</code></td><td>Log errors that prevent a flow from completing successfully.</td></tr><tr><td><code>fatal</code></td><td>Log runtime errors that require immediate action.</td></tr><tr><td><code>off</code></td><td>Disable logging.</td></tr></tbody></table>

### Get the secure logger instance

Get the secure logger instance from the SDK:

```swift
// get securelog object from TSHPay sdk
let securelog = TSHPay.secureLog
```

In production, keep `warn` in normal conditions.

For issue reproduction, let the end user enable a more verbose level. Then reproduce the issue and share the log files.

### Disable secure logger

To disable secure logger:

```swift
// By setting the level to off, logs are disabled. MPA can turn it on by selecting a different level. For example, debug
securelog.setLevel(.off)
```

### Retrieve log files

To retrieve the log files:

```swift
// return list of files
let files = securelog.files()
```

### Delete log files

To delete the log files:

```swift
// delete files
securelog.deleteFiles()
```

### Share log files (example)

This example shares logs using `UIActivityViewController`.

Your digital wallet application can also upload logs to a file server.

You can also send logs through other approved channels.

{% code expandable="true" %}

```swift
// share logs
    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 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://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/additional-features/collect-logs-with-secure-logger.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.
