Skip to content

Commit

Permalink
Merge branch '5' into 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jan 14, 2025
2 parents 9030a13 + ea19f7a commit 7df0686
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions en/02_Developer_Guides/07_Debugging/01_Error_Handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ icon: exclamation-circle

# Logging and error handling

Silverstripe CMS uses Monolog for both error handling and logging. It comes with two default configurations: one for
Silverstripe CMS uses Monolog for both error handling (for PHP errors and uncaught exceptions) and logging. It comes with two default configurations: one for
logging, and another for core error handling. The core error handling implementation also comes with two default
configurations: one for development environments, and another for test or live environments. On development
environments, Silverstripe CMS will deal harshly with any warnings or errors: a full call-stack is shown and execution
Expand Down Expand Up @@ -196,7 +196,15 @@ SilverStripe\Core\Injector\Injector:

The `info` argument provides the minimum level to start logging at.

### Disabling the default handler
### Modifying the default error handler

The default error handler catches uncaught exceptions and PHP errors and displays them in the browser and terminal.

> [!WARNING]
> In general you should not attach your own error handler to the `Psr\Log\LoggerInterface.errorhandler` error handler service.
> Attaching a your handler to the `Psr\Log\LoggerInterface` service will allow you to handle unchaught exceptions, PHP errors, and manually logged error messages, and is therefore preferred.

#### Disabling the default error handler

You can disable a handler by removing its pushHandlers call from the calls option of the Logger service definition.
The handler key of the default handler is `pushDisplayErrorHandler`, so you can disable it like this:
Expand All @@ -208,7 +216,7 @@ SilverStripe\Core\Injector\Injector:
pushDisplayErrorHandler: '%%remove%%'
```

### Setting a different configuration for dev
#### Setting a different configuration for dev

In order to set different logging configuration on different environment types, we rely on the environment-specific
configuration features that the config system providers. For example, here we have different configuration for dev and
Expand Down
4 changes: 2 additions & 2 deletions en/06_Upgrading/07_Deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ By default, deprecation warnings will be emitted to the error logger, and will b

### Viewing deprecation warnings in the logs

Deprecation warnings are output to the same error logger as all other warnings and errors. You will need to make sure you have a logging handler attached to the default `Psr\Log\LoggerInterface` or `Psr\Log\LoggerInterface.errorhandler` singletons. For example, to log to a file you can add this to your YAML configuration:
Deprecation warnings are output to the same error logger as all other warnings and errors. You will need to make sure you have a logging handler attached to the default `Psr\Log\LoggerInterface` singleton. For example, to log to a file you can add this to your YAML configuration:

```yml
SilverStripe\Core\Injector\Injector:
Expand All @@ -62,7 +62,7 @@ SilverStripe\Core\Injector\Injector:
constructor:
- "/var/www/silverstripe.log"
- "warning" # warning is the level deprecation warnings are logged as
Psr\Log\LoggerInterface.errorhandler:
Psr\Log\LoggerInterface:
calls:
ErrorLogFileHandler: [ pushHandler, [ '%$ErrorLogFileHandler' ] ]
```
Expand Down

0 comments on commit 7df0686

Please sign in to comment.