Skip to content

Commit

Permalink
chore: add info about logging and debugging (#363)
Browse files Browse the repository at this point in the history
Co-authored-by: Luis Moreno <[email protected]>
  • Loading branch information
morenol and morenol authored Feb 21, 2025
1 parent edcc3d3 commit a58249b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
6 changes: 3 additions & 3 deletions sdf/concepts/operator-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ SDF operators can access metadata and context information from the SDF engine us

In particular, we have available the following functions:

* [`window()`](#window-function) (Since sdf-beta7)
* [`key()`](#key-function) (Since sdf-beta7)
* [`sql()`](sql.mdx) (Since sdf-beta6)
* [`window()`](#window-function)
* [`key()`](#key-function)
* [`sql()`](sql.mdx)

## `window()` Function

Expand Down
30 changes: 30 additions & 0 deletions sdf/how-to/operator_logging.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Operator Logging
description: Logging within SDF operators using stdout and the `sdf log` command.
sidebar_position: 1200
---

SDF operators can output logs using standard output (stdout), which can then be viewed using the [`sdf log`](../cli/log) command. This allows developers to debug and monitor the behavior of their operators.

Within Rust operators, you can use the standard `println!` macro to write to stdout. The output will be captured and displayed when you execute `sdf log`.

This is particularly useful for debugging and understanding the context in which your operator is running. You can, for example, print the key using [`key()`](../concepts/operator-context.mdx#key-function) or the window boundaries using [`window()`](../concepts/operator-context.mdx#window-function).

## Example

Code example of an update-state operator with some output sent to standard output.

```rust
fn add_count(input: String) -> Result<()> {
if let Some(k) = key() {
println!("Key: {:?}", k); // Print the key if it exists
}

let (window_start, window_end) = window();
println!("Window start timestamp: {}, Window end timestamp: {}", window_start, window_end);

let new_value = counter().increment(1);
println!("New counter value: {}", new_value);

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ SDF operators can access metadata and context information from the SDF engine us

In particular, we have available the following functions:

* [`window()`](#window-function) (Since sdf-beta7)
* [`key()`](#key-function) (Since sdf-beta7)
* [`sql()`](sql.mdx) (Since sdf-beta6)
* [`window()`](#window-function)
* [`key()`](#key-function)
* [`sql()`](sql.mdx)

## `window()` Function

Expand Down
30 changes: 30 additions & 0 deletions sdf_versioned_docs/version-sdf-beta7/how-to/operator_logging.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Operator Logging
description: Logging within SDF operators using stdout and the `sdf log` command.
sidebar_position: 1200
---

SDF operators can output logs using standard output (stdout), which can then be viewed using the [`sdf log`](../cli/log) command. This allows developers to debug and monitor the behavior of their operators.

Within Rust operators, you can use the standard `println!` macro to write to stdout. The output will be captured and displayed when you execute `sdf log`.

This is particularly useful for debugging and understanding the context in which your operator is running. You can, for example, print the key using [`key()`](../concepts/operator-context.mdx#key-function) or the window boundaries using [`window()`](../concepts/operator-context.mdx#window-function).

## Example

Code example of an update-state operator with some output sent to standard output.

```rust
fn add_count(input: String) -> Result<()> {
if let Some(k) = key() {
println!("Key: {:?}", k); // Print the key if it exists
}

let (window_start, window_end) = window();
println!("Window start timestamp: {}, Window end timestamp: {}", window_start, window_end);

let new_value = counter().increment(1);
println!("New counter value: {}", new_value);

Ok(())
}

0 comments on commit a58249b

Please sign in to comment.