diff --git a/README.md b/README.md index e78a1fb..fe9b081 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,64 @@ Install with composer: composer require silverleague/logviewer ``` -## Configuration - This is a plug and play module. Simply install, then run a `dev/build` and flush: ```shell sake dev/build flush=1 ``` -You will now see a "Logs" tab in the CMS. +You will now see a "Logs" tab in the CMS: + +![Preview](docs/images/preview-list.jpg) + +## Configuration + +There are a few configuration options for this module. These can be modified in your YAML configuration, for example - `mysite/_config/logviewer.yml`: + +```yml +--- +Name: mysitelogviewer +After: + - '#logviewerconfig' +--- +# Configuration for the cleanup task +LogViewer: + # Whether the cleanup task should be run by a cron task (you need to figure the cron yourself) + # Type: bool + cron_enabled: true + # How often the cron should run (default: 4am daily) + # Type: string (a cron expression) + cron_schedule: 0 4 * * * + # The maximum age in days for a LogEntry before it will be removed by the cleanup task + # Type: int + max_log_age: 30 + # Which Monolog\Logger levels (numeric) to start handling from (see class for examples) + minimum_log_level: 300 # WARNING +``` + +While this is a copy of the default configuration, if the default configuration hadn't already existed or was different then this configuration would tell LogViewer that you _do_ want it to clean up log entries older than 30 days on a cron schedule at 4am each day. You also only want to keep logs that are "WARNING" level or higher (see `Monolog\Logger` for all available levels). + +### Testing + +There is an [example `BuildTask` in this repository](docs/examples/CreateLogsTask.php) which you can use to generate one of every PSR-3 log level for the sake of testing. + +The screenshot above is a result of having run it, using the configuration in the example above. + +## Cleaning up + +As mentioned previously, if you have an actively running `silverstripe/crontask` module already, the `RemoveOldLogEntriesTask` will run by default at 4am every morning and will remove log entries that are older than 30 days. + +You can run the task manually from the command line using `sake` or [`ssconsole`](https://github.com/silverleague/silverstripe-console): + +```shell +# With sake: +sake dev/tasks/RemoveOldLogEntriesTask + +# With ssconsole: +ssconsole dev:tasks:remove-old-log-entries +``` + +You can also remove **all log entries entirely** from the Logs interface in the admin area, by clicking "Clear all". This will clear all logs, not just those older than 30 days. ## Support diff --git a/_config/config.yml b/_config/config.yml index 022e2ea..45bb29c 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -13,10 +13,11 @@ SilverStripe\Core\Injector\Injector: # Configuration for the cleanup task LogViewer: # Whether the cron functionality should run. This does not affect use as a BuildTask. + # Note: you need to configure silverstripe/crontask yourself. cron_enabled: true # How often the cron should run (default: 4am daily) cron_schedule: 0 4 * * * # The maximum age in days for a LogEntry before it will be removed max_log_age: 30 - # Which Monolog\Logger levels (numberic) to start handling from (see class for examples) + # Which Monolog\Logger levels (numeric) to start handling from (see class for examples) minimum_log_level: 300 # WARNING diff --git a/docs/_manifest_exclude b/docs/_manifest_exclude new file mode 100644 index 0000000..e69de29 diff --git a/docs/examples/CreateLogsTask.php b/docs/examples/CreateLogsTask.php new file mode 100644 index 0000000..2ebee02 --- /dev/null +++ b/docs/examples/CreateLogsTask.php @@ -0,0 +1,43 @@ + + */ +class CreateLogsTask extends BuildTask +{ + /** + * {@inheritDoc} + */ + private static $segment = 'CreateLogsTask'; + + /** + * {@inheritDoc} + */ + public function run($request) + { + $logger = Injector::inst()->get('Logger'); + $logger->addDebug('Detailed debug information'); + $logger->addInfo('Interesting events. Examples: User logs in, SQL logs.'); + $logger->addNotice('Uncommon events'); + $logger->addWarning( + 'Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, ' + . 'undesirable things that are not necessarily wrong.' + ); + $logger->addError('Runtime errors'); + $logger->addCritical('Critical conditions. Example: Application component unavailable, unexpected exception.'); + $logger->addAlert( + 'Action must be taken immediately. Example: Entire website down, database unavailable, etc. ' + . 'This should trigger the SMS alerts and wake you up.' + ); + $logger->addEmergency('Urgent alert.'); + echo 'Finito.', PHP_EOL; + } +} diff --git a/docs/images/preview-list.jpg b/docs/images/preview-list.jpg new file mode 100644 index 0000000..003a3dc Binary files /dev/null and b/docs/images/preview-list.jpg differ diff --git a/src/Forms/GridField/GridFieldClearAllButton.php b/src/Forms/GridField/GridFieldClearAllButton.php index 630478a..fc207ee 100644 --- a/src/Forms/GridField/GridFieldClearAllButton.php +++ b/src/Forms/GridField/GridFieldClearAllButton.php @@ -41,7 +41,7 @@ public function getHTMLFragments($gridField) { $button = GridField_FormAction::create($gridField, 'clear', 'Clear all', 'clear', null); $button->setAttribute('data-icon', 'clear-all-logs'); - $button->addExtraClass('font-icon-trash-bin action_clear'); + $button->addExtraClass('font-icon-trash-bin action_clear action action-delete'); $button->setForm($gridField->getForm()); return [$this->targetFragment => '

' . $button->Field() . '

'];