Skip to content

Commit 7673a84

Browse files
Merge pull request #92 from julienloizelet/fix/add-debug-log-if-no-logger
feat(debug): Add debug log if bouncer logger is not ready
2 parents 640c43e + 1dc2e0c commit 7673a84

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

.github/workflows/end-to-end-auto-prepend-test-suite.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: End-to-end auto-prepend-file mode test suite
22
on:
33
push:
4+
branches:
5+
- main
46
paths-ignore:
57
- '**.md'
68
workflow_dispatch:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [1.4.2] - 2022-05-13
8+
9+
### Added
10+
- Add WordPress debug log if bouncer logger is not ready
11+
712
## [1.4.1] - 2022-04-10
813

914
### Fixed

crowdsec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/crowdsecurity/cs-wordpress-bouncer
55
* Description: Safer Together. Protect your WordPress application with CrowdSec.
66
* Tags: crowdsec-bouncer, wordpress, security, firewall, captcha, ip-scanner, ip-blocker, ip-blocking, ip-address, ip-database, ip-range-check, crowdsec, ban-hosts, ban-management, anti-hacking, hacker-protection, captcha-image, captcha-generator, captcha-generation, captcha-service
7-
* Version: 1.4.1
7+
* Version: 1.4.2
88
* Author: CrowdSec
99
* Author URI: https://www.crowdsec.net/
1010
* Github: https://github.com/crowdsecurity/cs-wordpress-blocker
@@ -13,7 +13,7 @@
1313
* Requires PHP: 7.2
1414
* Requires at least: 4.9
1515
* Tested up to: 5.9
16-
* Stable tag: 1.4.1
16+
* Stable tag: 1.4.2
1717
* Text Domain: crowdsec-wp
1818
* First release: 2021.
1919
*/

inc/Bounce.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,21 @@ public function safelyBounce(array $configs): bool
336336
$this->run();
337337
$result = true;
338338
} catch (\Exception $e) {
339-
$this->logger->error('', [
340-
'type' => 'WP_EXCEPTION_WHILE_BOUNCING',
341-
'message' => $e->getMessage(),
342-
'code' => $e->getCode(),
343-
'file' => $e->getFile(),
344-
'line' => $e->getLine(),
345-
]);
339+
if(!$this->logger){
340+
// Try to log in the debug.log file of WordPress if bouncer logger is not ready
341+
error_log(print_r('safelyBounce error:' . $e->getMessage() .
342+
' in file:' . $e->getFile() .
343+
'(line ' . $e->getLine() . ')', true
344+
));
345+
} else {
346+
$this->logger->error('', [
347+
'type' => 'WP_EXCEPTION_WHILE_BOUNCING',
348+
'message' => $e->getMessage(),
349+
'code' => $e->getCode(),
350+
'file' => $e->getFile(),
351+
'line' => $e->getLine(),
352+
]);
353+
}
346354
if ($this->displayErrors) {
347355
throw $e;
348356
}

inc/constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ function crowdsecDefineConstants(string $crowdsecRandomLogFolder)
88
define('CROWDSEC_DEBUG_LOG_PATH', __DIR__."/../logs/$crowdsecRandomLogFolder/debug.log");
99
define('CROWDSEC_CACHE_PATH', __DIR__.'/../.cache');
1010
define('CROWDSEC_CONFIG_PATH', __DIR__.'/standalone-settings.php');
11-
define('CROWDSEC_BOUNCER_USER_AGENT', 'WordPress CrowdSec Bouncer/v1.4.1');
11+
define('CROWDSEC_BOUNCER_USER_AGENT', 'WordPress CrowdSec Bouncer/v1.4.2');
1212
}
1313
}

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://crowdsec.net/
44
Tags: crowdsec-bouncer, wordpress, security, firewall, captcha, ip-scanner, ip-blocker, ip-blocking, ip-address, ip-database, ip-range-check, crowdsec, ban-hosts, ban-management, anti-hacking, hacker-protection, captcha-image, captcha-generator, captcha-generation, captcha-service
55
Requires at least: 4.9
66
Tested up to: 5.9
7-
Stable tag: 1.4.1
7+
Stable tag: 1.4.2
88
Requires PHP: 7.2
99
License: MIT
1010
License URI: https://opensource.org/licenses/MIT

0 commit comments

Comments
 (0)