Survey Logger Class
survey_logger.RdR6 Class providing dual logging functionality for Shiny survey applications: console messaging and database logging of survey metadata.
Details
The logger provides two distinct logging mechanisms:
Console Logging (log_message):
Immediate color-coded console output for app messages, warnings, and errors
No database persistence - console only
Supports custom zones/contexts for message categorization
Database Logging (log_entry):
Queued logging of survey metadata to database table
Tracks survey completion metrics (timing, errors, SQL statements)
Uses batch processing with automatic queue management
Only logs database errors after survey is loaded (conditional logging)
Key Features:
Dual-purpose logging: console messages + database survey metadata
Uses main application connection for database operations
Efficient batch database writes with automatic queue processing
Immediate console feedback with color coding and zone support
Database connection health monitoring
SQL statement tracking for database error debugging
Console Message Types
INFO: Regular informational messages (green console output)WARN: Warning messages (yellow console output)ERROR: Error messages (red console output)
Public fields
log_tableCharacter string specifying the database table for logs
session_idCharacter string containing unique session identifier
table_nameCharacter string identifying the current table
survey_loadedLogical flag indicating if a survey has been successfully loaded
suppress_logsLogical flag to suppress console output
queuedata.frame containing queued messages for batch processing
last_sqlCharacter string containing the last executed SQL statement
Methods
Method new()
Initialize a new survey logger instance
Usage
survey_logger$new(log_table, session_id, table_name, echo = TRUE)Method log_entry()
Queue a log entry for database insert (only for loaded surveys)
Usage
survey_logger$log_entry(
table_id,
message = NULL,
ip_address = NULL,
duration_load = NULL,
duration_complete = NULL,
duration_save = NULL,
sql = NULL,
force_log = FALSE
)Arguments
table_idInteger ID from the table
messageCharacter string containing error message (only for DB errors after survey loaded)
ip_addressCharacter string containing client IP address
duration_loadNumeric time spent loading (seconds)
duration_completeNumeric time spent completing survey (seconds)
duration_saveNumeric time spent saving (seconds)
sqlCharacter string containing the SQL that failed (only for errors)
force_logLogical flag to force logging even if survey not loaded (internal use)
Method log_message()
Helper method for simple console logging (no database)