Skip to content

Latest commit

 

History

History
62 lines (50 loc) · 2.74 KB

log_method_parameter_values.md

File metadata and controls

62 lines (50 loc) · 2.74 KB

How to log method parameters values

Contents

Problem

You want to log what the parameters are that a method receives at the method start (and end)

Logging Inputs

To log the input values, you can pass in a formatted string to SimpleLogger.use_markers.
Here is an example:

def method_with_inputs(number, name):
    with SimpleLogger.use_markers(f"number = {number}, name = {name}"):

snippet source | anchor

It will produce:

-> in: method_with_inputs(number = 1, name = Susan) in test_simple_logger
<- out: method_with_inputs()

snippet source | anchor

Logging Inputs and Outputs

To log the values at both entrance to the method and exit from the method, you can pass in a formatted string in a lambda.
Here is an example:

def method_with_inputs_and_outputs(number, announcement):
    with SimpleLogger.use_markers(
        lambda: f"number = {number}, announcement = {announcement}"
    ):

snippet source | anchor

It will produce:

-> in: method_with_inputs_and_outputs(number = 10, announcement = Blast off) in test_simple_logger
<- out: method_with_inputs_and_outputs(number = 1, announcement = Blast off)

snippet source | anchor