Shiny App Logger Class
survey_logger.Rd
An R6 class that provides asynchronous logging functionality for shiny app messages.
Details
This class handles asynchronous logging of shiny app messages to a PostgreSQL database. It uses connection pooling and futures for efficient database operations. The class maintains a single logging table per instance and handles all database connections internally.
Message Types
The logger supports different message types that are displayed with distinct visual styles:
- INFO
Regular informational messages (displayed in green)
- WARN
Warning messages (displayed in yellow)
- ERROR
Error messages (displayed in red)
Public Fields
- log_table
character. Name of the database table for logging
- session_id
character. Unique identifier for the current session
- survey_name
character. Name of the survey being logged
- db_params
list. Database connection parameters
Methods
- initialize(log_table, session_id, survey_name, db_config = NULL)
Creates a new logger instance
- log_table
character. Name of the logging table
- session_id
character. Unique session identifier
- survey_name
character. Name of the survey
- db_config
list. Optional database configuration parameters
- log_message(message, type = "INFO", zone = "DEFAULT")
Logs a message asynchronously with appropriate visual styling
- message
character. Message to log
- type
character. Type of message ("INFO", "WARN", "ERROR")
- zone
character. Zone identifier for message categorization
Public fields
log_table
Name of the database table for logging
session_id
Unique identifier for the current session
survey_name
Name of the survey being logged
db_params
List of database connection parameters
Methods
Method new()
Initialize a new survey logger instance
Usage
survey_logger$new(log_table, session_id, survey_name)
Method log_message()
Log a message asynchronously to the database with appropriate visual styling
Examples
if (FALSE) { # \dontrun{
# Initialize logger
logger <- survey_logger$new(
log_table = "survey_logs",
session_id = "user123",
survey_name = "customer_feedback"
)
# Log different types of messages
logger$log_message("Survey started", "INFO", "initialization")
logger$log_message("Missing optional field", "WARN", "validation")
logger$log_message("Required field empty", "ERROR", "validation")
} # }