Overview
POS Kasir implements a comprehensive activity logging system that tracks all significant user actions and system events. Activity logs provide an audit trail for security, compliance, and troubleshooting purposes.Activity Log System
Get Activity Logs
Retrieve activity logs with filtering and pagination. Endpoint:GET /activity-logs
Required Role: Admin
internal/activitylog/handler.go:25-78
page- Page number (default: 1)limit- Items per page (default: 10, max: 100)search- Search term (searches in details)start_date- Start date (YYYY-MM-DD)end_date- End date (YYYY-MM-DD)user_id- Filter by user ID (UUID)entity_type- Filter by entity typeaction_type- Filter by action type
Entity Types
Activity logs track actions across different entity types:internal/activitylog/dto.go:17
- PRODUCT - Product-related actions (create, update, delete, restore)
- CATEGORY - Category management actions
- PROMOTION - Promotion configuration changes
- ORDER - Order lifecycle events
- USER - User management and authentication events
Action Types
The system logs various action types:internal/activitylog/dto.go:18
General Actions
- CREATE - Entity created
- UPDATE - Entity updated
- DELETE - Entity deleted
Order-Specific Actions
- CANCEL - Order cancelled
- APPLY_PROMOTION - Promotion applied to order
- PROCESS_PAYMENT - Payment processed
User-Specific Actions
- REGISTER - New user registered
- UPDATE_PASSWORD - Password changed
- UPDATE_AVATAR - Profile picture updated
- LOGIN_SUCCESS - Successful login attempt
- LOGIN_FAILED - Failed login attempt
Activity Logging in Code
User Registration Example
internal/user/auth_service.go:264-282
Password Update Example
internal/user/auth_service.go:116-134
Login Tracking Example
internal/user/auth_service.go:309-364
Avatar Update Example
internal/user/auth_service.go:186-202
Activity Log Data Structure
internal/activitylog/dto.go:21-30
Log Details Field
Thedetails field is a flexible JSON object that stores context-specific information:
User Actions:
Request DTO
internal/activitylog/dto.go:10-19
Use Cases
Security Audit
Track failed login attempts:User Activity Tracking
Monitor specific user’s actions:Order Audit Trail
Track all actions on a specific order:Daily Activity Report
Generate activity summary for a specific date:Compliance Reporting
Track sensitive operations:Logged Actions by Feature
Authentication & User Management
- User login (success/failure)
- User logout
- Password changes
- Profile updates
- Avatar uploads
- User creation
- Role changes
- User status toggles
Order Management
- Order creation
- Order status updates
- Order cancellation
- Payment processing
- Promotion application
- Order item modifications
Inventory Management
- Product creation
- Product updates
- Product deletion
- Stock adjustments
- Category changes
- Image uploads
System Configuration
- Settings updates
- Payment method changes
- Promotion configuration
Best Practices
- Contextual Information - Always include relevant details in the log details field
- User Identification - Capture actor ID from context for all logged actions
- Sensitive Data - Never log passwords or payment card details
- Retention Policy - Implement log retention and archival policies
- Search Optimization - Index commonly queried fields (user_id, entity_type, action_type, created_at)
- Async Logging - Log activities asynchronously to avoid impacting request performance
- Error Handling - Gracefully handle logging failures without affecting main operations
- Regular Reviews - Periodically review logs for security incidents and anomalies
Performance Considerations
- Activity logs can grow rapidly; consider:
- Database partitioning by date
- Archiving old logs to cold storage
- Elasticsearch for advanced search capabilities
- Async logging to prevent request blocking
- Background jobs for heavy analytics
Security Considerations
Access Control
- Only Admins can access activity logs
- Logs are read-only (no update/delete operations)
- All log access is itself logged
Data Protection
- Redact sensitive information from details field
- Implement log encryption at rest
- Secure log transmission in distributed systems
- Regular security audits of logged data
Related Features
- Authentication - Login/logout logging
- User Management - User action tracking
- Orders & POS - Order event logging
- Inventory Management - Product change tracking