<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "os",
  "identifier" : "/documentation/os/Logger",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "os"
    ],
    "preciseIdentifier" : "s:2os6LoggerV"
  },
  "title" : "Logger"
}
-->

# Logger

An object for writing interpolated string messages to the unified logging system.

```
struct Logger
```

## Overview

Create a [`Logger`](/documentation/os/Logger) structure and use it to log messages about your app’s behavior. When logging a message, you specify the message and any program variables or custom data to help you assess the state of your app. You also choose a log level to indicate the severity of that message. The system records log messages in memory and, in some cases, also writes those messages to an on-disk data store. The log level determines which messages stay in memory and which go to disk.

When you create a [`Logger`](/documentation/os/Logger) structure, assign an optional subsystem and category string to add context to all messages you log. A subsystem corresponds to a large functional area of your app, and a category corresponds to a specific area within a particular subsystem. When diagnosing problems, use those strings to filter out unrelated messages.

To log a message, call the method that represents the appropriate log level for that message. To create the message, use a Swift string. Strings may contain interpolated values, such as signed and unsigned integers, floating-point and double values, Booleans, other strings, Objective-C objects, and types that conform to the <doc://com.apple.documentation/documentation/Swift/CustomStringConvertible> protocol. You can also include metatypes such as `Int.self`.

```swift
let logger = Logger()
let x = 42
logger.info("The answer is \(x)")
```

When you include an interpolated string or custom object in your message, the system redacts the value of that string or object by default. This behavior prevents the system from leaking potentially user-sensitive information in the log files, such as the user’s account information. If the data doesn’t contain sensitive information, change the privacy option of that value when logging the information. In the following code example, the system redacts the account information in the first log message, but displays the user’s selection in the second log message:

```swift
logger.log("Paid with bank account \(accountNumber)")   // Redacted!
logger.log("Ordered smoothie \(smoothieName, privacy: .public)")  // Visible
```

## Topics

### Creating a Logger

[`init()`](/documentation/os/Logger/init())

Creates a logger that writes to the default subsystem.

[`init(subsystem:category:)`](/documentation/os/Logger/init(subsystem:category:))

Creates a logger using the specified subsystem and category.

[`init(_:)`](/documentation/os/Logger/init(_:))

Creates a logger that writes to the specified log.

[`OSLog`](/documentation/os/OSLog)

A container of related log messages.

### Logging a Message

[`log(_:)`](/documentation/os/Logger/log(_:))

Writes a message to the log using the default log type.

[`log(level:_:)`](/documentation/os/Logger/log(level:_:))

Writes a message to the log using the specified log type.

[`OSLogType`](/documentation/os/OSLogType)

The various log levels that the unified logging system provides.

[`OSLogMessage`](/documentation/os/OSLogMessage)

An object that represents a log message.

### Logging a Scoped Message

[`notice(_:)`](/documentation/os/Logger/notice(_:))

Writes a message to the log using the default log type.

[`debug(_:)`](/documentation/os/Logger/debug(_:))

Writes a debug message to the log.

[`trace(_:)`](/documentation/os/Logger/trace(_:))

Writes a trace message to the log.

[`info(_:)`](/documentation/os/Logger/info(_:))

Writes an informative message to the log.

[`error(_:)`](/documentation/os/Logger/error(_:))

Writes information about an error to the log.

[`warning(_:)`](/documentation/os/Logger/warning(_:))

Writes information about a warning to the log.

[`fault(_:)`](/documentation/os/Logger/fault(_:))

Writes a message to the log about a bug that occurs when your app executes.

[`critical(_:)`](/documentation/os/Logger/critical(_:))

Writes a message to the log about a critical event in your app’s execution.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)