<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Combine",
  "identifier" : "/documentation/Combine/Publisher/print(_:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAE5print_2toAA10PublishersO5PrintVy_xGSS_s16TextOutputStream_pSgtF"
  },
  "title" : "print(_:to:)"
}
-->

# print(_:to:)

Prints log messages for all publishing events.

```
func print(_ prefix: String = "", to stream: (any TextOutputStream)? = nil) -> Publishers.Print<Self>
```

## Parameters

`prefix`

A string —- which defaults to empty -— with which to prefix all log messages.

`stream`

A stream for text output that receives messages, and which directs output to the console by default.  A custom stream can be used to log messages to other destinations.

## Return Value

A publisher that prints log messages for all publishing events.

## Discussion

Use [`print(_:to:)`](/documentation/Combine/Publisher/print(_:to:)) to log messages the console.

In the example below, log messages are printed on the console:

```
let integers = (1...2)
cancellable = integers.publisher
   .print("Logged a message", to: nil)
   .sink { _ in }

// Prints:
//  Logged a message: receive subscription: (1..<2)
//  Logged a message: request unlimited
//  Logged a message: receive value: (1)
//  Logged a message: receive finished
```

---

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)