Logging
Effective logging is crucial for monitoring, debugging, and auditing activities within your admin panel. The go-advanced-admin provides a flexible logging system that you can configure to suit your needs. This guide will walk you through configuring logging levels, using the default log store, and integrating a custom log store such as a database-backed log store.
Overview
The logging system in go-advanced-admin is designed to be:
Configurable: Adjust the verbosity and types of logs you receive.
Extensible: Use the default in-memory log store or integrate your own.
Informative: Keep track of actions like CRUD operations, user interactions, and system events.
Configuring the Log Store Level
The log store level determines the types of actions that are recorded in the logs. By configuring this level, you can control the verbosity of your logging system.
Available Log Levels
The following log levels are available:
LogStoreLevelDelete
: Logs delete actions.LogStoreLevelCreate
: Logs create actions.LogStoreLevelUpdate
: Logs update actions.LogStoreLevelInstanceView
: Logs when an instance is viewed.LogStoreLevelListView
: Logs when a list of instances is viewed.LogStoreLevelPanelView
: Logs when the admin panel is accessed.
Setting the Log Level
You can set the log level when initializing your admin panel configuration:
Note: Setting a higher log level includes all the lower levels. For example, setting LogStoreLevelUpdate
will log update actions and all actions with higher importance (create and delete).
Using the Default Log Store
By default, go-advanced-admin uses an in-memory log store that retains a limited number of log entries.
Features of the Default Log Store
In-Memory Storage: Logs are stored in memory, suitable for development and testing.
Limited Capacity: Configurable maximum number of log entries to prevent memory overflow.
FIFO Policy: Oldest logs are discarded when the capacity is exceeded.
Configuring the Default Log Store
You can adjust the capacity of the default log store during initialization:
Building a Custom Log Store
For production environments or advanced logging needs, you might want to store logs in a persistent storage like a database. You can achieve this by implementing a custom log store.
Implementing the Required Interface
Your custom log store must implement the LogStore
interface defined in the logging
package:
Handling Log Messages
Implement the methods to handle log entries according to your storage medium.
Example: Database-Backed Log Store
Here's a simplified example using GORM to store logs in a database.
Registering the Custom Log Store
Once your custom log store is implemented, you can register it in your admin panel configuration:
Contributing Your Log Store
If you've built a custom log store that you believe could benefit others, we encourage you to contribute it back to the community!
Steps to Contribute
Fork the Repository: Start by forking the go-advanced-admin repository.
Add Your Log Store: Implement your log store in the appropriate package or create a new one.
Write Tests: Ensure your log store is well-tested.
Update Documentation: Provide documentation and examples for others to use.
Submit a Pull Request: Open a pull request with a detailed description of your contribution.
Contribution Guidelines
Please refer to our Contribution Guide for detailed instructions on how to contribute code, report issues, and suggest enhancements.
Your contributions help make go-advanced-admin better for everyone!
References
Quick Start Guide: Get started quickly by following our Quick Start Guide.
Permissions: Learn how to set up permissions in the Permissions Guide.
Issue Tracker: Report issues or request features on our
Next Steps:
Explore the Advanced Topics for more customization options.
Read about Templates to customize the UI.
Thank you for using go-advanced-admin!