# Create a basic Stenographer
steno <- Stenographer$new()
steno$info("This is an info message")
steno$warn("This is a warning")
steno$error("This is an error")
# Disable all logging
steno$set_level(LogLevel$OFF)
steno$info("This won't be logged")
steno$warn("This won't be logged either")
steno$error("This also won't be logged")
# Create a logger with custom settings, message formatting, and context
custom_steno <- Stenographer$new(
level = LogLevel$WARNING,
file_path = tempfile("log_"),
print_fn = function(x) message(paste0("Custom: ", x)),
format_fn = function(level, msg) paste0("Hello prefix: ", msg),
context = list(program = "MyApp")
)
custom_steno$info("This won't be logged")
custom_steno$warn("This will be logged with a custom prefix")
# Change log level and update context
custom_steno$set_level(LogLevel$INFO)
custom_steno$update_context(list(user = "John"))
custom_steno$info("Now this will be logged with a custom prefix and context")
Run the code above in your browser using DataLab