---
title: "print(_:to:)"
framework: combine
role: symbol
role_heading: Instance Method
path: "combine/publisher/print(_:to:)"
---

# print(_:to:)

Prints log messages for all publishing events.

## Declaration

```swift
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

Return Value A publisher that prints log messages for all publishing events.

## Discussion

Discussion Use 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

## See Also

### Debugging

- [breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)](combine/publisher/breakpoint(receivesubscription:receiveoutput:receivecompletion:).md)
- [breakpointOnError()](combine/publisher/breakpointonerror().md)
- [handleEvents(receiveSubscription:receiveOutput:receiveCompletion:receiveCancel:receiveRequest:)](combine/publisher/handleevents(receivesubscription:receiveoutput:receivecompletion:receivecancel:receiverequest:).md)
