ActivityLoggingTrait
Trait for standardized activity logging across Canvas LMS API classes.
This trait provides consistent logging methods for API operations, including activity tracking, performance metrics, and error handling.
Table of Contents
Methods
- endTimer() : void
- End a timed operation and log the performance.
- getActivityLogger() : LoggerInterface
- Get the logger instance for activity logging.
- logActivity() : void
- Log an API activity with enriched context.
- logError() : void
- Log an API error with context.
- logFileUpload() : void
- Log file upload operations.
- logOAuthOperation() : void
- Log OAuth token operations.
- logPagination() : void
- Log pagination information.
- logPerformance() : void
- Log performance metrics for an operation.
- logSuccess() : void
- Log a successful API operation.
- startTimer() : float
- Start a timed operation for performance logging.
- sanitizeOAuthContext() : array<string, mixed>
- Sanitize OAuth context to remove sensitive data.
Methods
endTimer()
End a timed operation and log the performance.
protected
endTimer(float $startTime, string $operation[, array<string, mixed> $context = [] ]) : void
Parameters
- $startTime : float
-
The start time from startTimer()
- $operation : string
-
The operation being measured
- $context : array<string, mixed> = []
-
Additional context
getActivityLogger()
Get the logger instance for activity logging.
protected
getActivityLogger() : LoggerInterface
Return values
LoggerInterfacelogActivity()
Log an API activity with enriched context.
protected
logActivity(string $action[, array<string, mixed> $context = [] ]) : void
Parameters
- $action : string
-
The action being performed (e.g., 'fetch', 'create', 'update', 'delete')
- $context : array<string, mixed> = []
-
Additional context for the log entry
logError()
Log an API error with context.
protected
logError(string $operation, Throwable $exception[, array<string, mixed> $context = [] ]) : void
Parameters
- $operation : string
-
The operation that failed
- $exception : Throwable
-
The exception that was thrown
- $context : array<string, mixed> = []
-
Additional context for the log entry
logFileUpload()
Log file upload operations.
protected
logFileUpload(string $step[, array<string, mixed> $context = [] ]) : void
Parameters
- $step : string
-
The upload step (e.g., 'initiate', 'upload', 'confirm')
- $context : array<string, mixed> = []
-
Additional context for the log entry
logOAuthOperation()
Log OAuth token operations.
protected
logOAuthOperation(string $operation[, array<string, mixed> $context = [] ]) : void
Parameters
- $operation : string
-
The OAuth operation (e.g., 'refresh', 'validate', 'revoke')
- $context : array<string, mixed> = []
-
Additional context for the log entry
logPagination()
Log pagination information.
protected
logPagination(string $operation, int $page, int $perPage[, array<string, mixed> $context = [] ]) : void
Parameters
- $operation : string
-
The pagination operation
- $page : int
-
The current page number
- $perPage : int
-
The number of items per page
- $context : array<string, mixed> = []
-
Additional context for the log entry
logPerformance()
Log performance metrics for an operation.
protected
logPerformance(string $operation, float $duration[, array<string, mixed> $context = [] ]) : void
Parameters
- $operation : string
-
The operation being measured
- $duration : float
-
The duration in seconds
- $context : array<string, mixed> = []
-
Additional context for the log entry
logSuccess()
Log a successful API operation.
protected
logSuccess(string $operation[, array<string, mixed> $context = [] ]) : void
Parameters
- $operation : string
-
The operation that succeeded
- $context : array<string, mixed> = []
-
Additional context for the log entry
startTimer()
Start a timed operation for performance logging.
protected
startTimer() : float
Return values
float —The start time
sanitizeOAuthContext()
Sanitize OAuth context to remove sensitive data.
private
sanitizeOAuthContext(array<string, mixed> $context) : array<string, mixed>
Parameters
- $context : array<string, mixed>
-
The context to sanitize
Return values
array<string, mixed> —The sanitized context