Skip to content

Commit

Permalink
Added log support
Browse files Browse the repository at this point in the history
  • Loading branch information
solital committed May 1, 2024
1 parent 2e1a345 commit a303f6e
Show file tree
Hide file tree
Showing 16 changed files with 1,103 additions and 360 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
vendor/
composer.lock
indexTest.php
debug-test.php
debug.php
debug-test.php
tests.php
ModernPHPExceptionLogs.log
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Released Notes

## v3.2.0 - (2024-05-01)

### Added

- Added logs in `shutdown` method

### Changed

- Changed `var_dump_debug` and `dump_die` to accept multiple variables

### Fixed

- Fixed special chars in `errorHandler`

### Removed

- Removed `codedungeon/php-cli-colors` and `ghostff/dump7` packages
- Removed `MessageTrait` trait

--------------------------------------------------------------------------

## v3.1.2 - (2024-03-16)

### Fixed
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ error_message: Something wrong!
enable_cdn_assets: false
```
**Enabling Log file**
```yaml
enable_logs: false

# Default: sys_get_temp_dir() . "/ModernPHPExceptionLogs/ModernPHPExceptionLogs.log"
dir_logs: C:\wamp64\www\modern-php-exception\
```
## Enable occurrences
If you want to have a history of all exceptions and errors that your application displays, you can enable the occurrences using the `enableOccurrences` method:
Expand Down Expand Up @@ -168,7 +177,32 @@ echo var_dump_buffer()
var_dump_debug()
```

- Dump PHP value and die script
In terminal, you can simple hide or show some object attribute using a Doc block flag:

| | |
|-------------------------------|---------------------------------------------------|
| `@dumpignore-inheritance` | Hides inherited class properties. |
| `@dumpignore-inherited-class` | Hides the class name from inherited properties. |
| `@dumpignore-private` | Show all properties except the **private** ones. |
| `@dumpignore-protected` | Show all properties except the **protected** ones.|
| `@dumpignore-public` | Show all properties except the **public** ones. |
| `@dumpignore` | Hide the property the Doc comment belongs to. |

```php
/**
* @dumpignore-inheritance
* @dumpignore-inherited-class
* @dumpignore-private
* @dumpignore-public
* @dumpignore-public
*/
Class Foo extends Bar {
/** @dumpignore */
private ?BigObject $foo = null;
}
```

- Dump PHP value and die script. This function use `var_dump_debug`.

```php
dump_die()
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "brenno-duarte/modern-php-exception",
"description": "PHP errors in a modern way",
"license": "MIT",
"version": "3.1.2",
"version": "3.2.0",
"keywords": [
"exception",
"throwable",
Expand All @@ -16,9 +16,7 @@
"php": "^8.3",
"ext-mbstring": "*",
"ext-pdo": "*",
"codedungeon/php-cli-colors": "1.*",
"symfony/yaml": "^7.0",
"ghostff/dump7": "^2.0"
"symfony/yaml": "^7.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 4 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ error_message:
# Use `false` only if you have no internet connection
enable_cdn_assets: true

# Enable logs register
enable_logs: false
dir_logs:

# Database for Occurrences
db_drive: mysql
db_host: localhost
Expand Down
28 changes: 18 additions & 10 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

use Dump as GlobalDump;
use ModernPHPException\Resources\Dump;
use ModernPHPException\Console\CliMessage;
use ModernPHPException\Resources\BrowserDump;
use ModernPHPException\Resources\CliDump;

/**
* An easy function to pull all details of the debug backtrace
Expand Down Expand Up @@ -45,13 +46,20 @@ function var_dump_buffer(mixed $value): string|false
*
* @return void
*/
function var_dump_debug(mixed $value): void
function var_dump_debug(...$values): void
{
if (isCli() == true) {
new GlobalDump($value);
} else {
$result = call_user_func(array(new Dump(), 'dump'), $value);
echo $result;
foreach ($values as $value) {
if (isCli() == true) {
CliDump::set('string', ['0000FF', 'light_blue']);
new CliDump($value);

if (!CliMessage::colorIsSupported() || !CliMessage::are256ColorsSupported()) {
CliDump::safe($value);
}
} else {
$dump = new BrowserDump();
echo $dump->dump($value);
}
}
}

Expand All @@ -62,9 +70,9 @@ function var_dump_debug(mixed $value): void
*
* @return void
*/
function dump_die(mixed $value): void
function dump_die(...$values): void
{
var_dump_debug($value);
var_dump_debug($values);
exit;
}

Expand Down
Loading

0 comments on commit a303f6e

Please sign in to comment.