Skip to content

Commit

Permalink
DOCS Update readme to include a screenshot, configuration and cleanup…
Browse files Browse the repository at this point in the history
… examples

* Add confirmation to the "clear all" button
  • Loading branch information
robbieaverill committed Jan 9, 2017
1 parent e215199 commit a06b5cf
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
55 changes: 52 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file added docs/_manifest_exclude
Empty file.
43 changes: 43 additions & 0 deletions docs/examples/CreateLogsTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace SilverLeague\LogViewer\Task;

use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;

/**
* This is purely for demo purposes, and will log a message at every level for local testing or demo purposes.
*
* @package silverstripe-logviewer
* @author Robbie Averill <robbie@averill.co.nz>
*/
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;
}
}
Binary file added docs/images/preview-list.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldClearAllButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '<p class="grid-clear-all-button">' . $button->Field() . '</p>'];
Expand Down

0 comments on commit a06b5cf

Please sign in to comment.