Skip to content

Commit 5abadcb

Browse files
Merge pull request #103 from julienloizelet/feat/disable-prod-log
Feat/disable prod log
2 parents aab56fb + d0c3640 commit 5abadcb

File tree

11 files changed

+31
-16
lines changed

11 files changed

+31
-16
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
## [0.28.0] - 2022-08-04
9+
10+
### Changed
11+
- *Breaking change*: Rename `ClientAbstract` class to `AbstractClient`
12+
- Hide `api_key` in log.
13+
14+
### Added
15+
- Add `disable_prod_log` configuration
16+
817

918
## [0.27.0] - 2022-07-29
1019

docs/USER_GUIDE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,15 @@ Here is the list of available settings:
123123

124124
- `api_url`: Define the URL to your LAPI server, default to `http://localhost:8080`.
125125

126-
- `api_timeout`: In seconds. The timeout when calling LAPI. Must be greater or equal than 1. Defaults to 1 sec.
126+
- `api_timeout`: In seconds. The timeout when calling LAPI. Must be greater or equal than 1. Default to 1 sec.
127127

128128
- `use_curl`: By default, this lib call the REST LAPI using `file_get_contents` method (`allow_url_fopen` is required).
129129
You can set `use_curl` to `true` in order to use `cURL` request instead (`curl` is in then required)
130130

131131
##### Debug
132-
- `debug_mode`:true to enable verbose debug log.
132+
- `debug_mode`: `true` to enable verbose debug log. Default to `false`.
133133

134+
- `disable_prod_log`: `true` to disable prod log. Default to `false`.
134135

135136
- `log_directory_path`: Absolute path to store log files. Important note: be sur this path won't be publicly accessible
136137

scripts/auto-prepend/settings.example.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
// true to enable verbose debug log.
2929
'debug_mode' => false,
30+
// true to disable prod log
31+
'disable_prod_log' => false,
3032

3133
/** Absolute path to store log files.
3234
*

src/AbstractBounce.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ protected function initLoggerHelper(array $configs, string $loggerName): void
135135

136136
$this->logger = new Logger($loggerName);
137137
$logDir = $configs['log_directory_path']??__DIR__.'/.logs';
138-
$logPath = $logDir . '/prod.log';
139-
$fileHandler = new RotatingFileHandler($logPath, 0, Logger::INFO);
140-
$fileHandler->setFormatter(new LineFormatter("%datetime%|%level%|%context%\n"));
141-
$this->logger->pushHandler($fileHandler);
138+
if (empty($configs['disable_prod_log'])) {
139+
$logPath = $logDir . '/prod.log';
140+
$fileHandler = new RotatingFileHandler($logPath, 0, Logger::INFO);
141+
$fileHandler->setFormatter(new LineFormatter("%datetime%|%level%|%context%\n"));
142+
$this->logger->pushHandler($fileHandler);
143+
}
142144

143145
// Set custom readable logger when debug=true
144146
if (!empty($configs['debug_mode'])) {

src/ApiClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Psr\Log\LoggerInterface;
88
use CrowdSecBouncer\RestClient\FileGetContents;
99
use CrowdSecBouncer\RestClient\Curl;
10-
use CrowdSecBouncer\RestClient\ClientAbstract;
10+
use CrowdSecBouncer\RestClient\AbstractClient;
1111

1212
/**
1313
* The LAPI REST Client. This is used to retrieve decisions.
@@ -27,7 +27,7 @@ class ApiClient
2727
private $configs;
2828

2929
/**
30-
* @var ClientAbstract
30+
* @var AbstractClient
3131
*/
3232
private $restClient;
3333

@@ -88,7 +88,7 @@ public function getStreamedDecisions(
8888
);
8989
}
9090

91-
public function getRestClient(): ClientAbstract
91+
public function getRestClient(): AbstractClient
9292
{
9393
return $this->restClient;
9494
}

src/Bouncer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
require_once __DIR__ . '/templates/access-forbidden.php';
77

88
use CrowdSecBouncer\Fixes\Gregwar\Captcha\CaptchaBuilder;
9-
use CrowdSecBouncer\RestClient\ClientAbstract;
9+
use CrowdSecBouncer\RestClient\AbstractClient;
1010
use ErrorException;
1111
use Gregwar\Captcha\PhraseBuilder;
1212
use IPLib\Factory;
@@ -74,7 +74,7 @@ public function __construct(array $configs, LoggerInterface $logger = null)
7474
'type' => 'BOUNCER_INIT',
7575
'logger' => \get_class($this->logger),
7676
'max_remediation_level' => $this->maxRemediationLevelIndex,
77-
'configs' => $this->configs
77+
'configs' => array_merge($this->configs, ['api_key' => '***'])
7878
]);
7979
}
8080

@@ -317,7 +317,7 @@ public function getClient(): ApiClient
317317
return $this->getApiCache()->getClient();
318318
}
319319

320-
public function getRestClient(): ClientAbstract
320+
public function getRestClient(): AbstractClient
321321
{
322322
return $this->getClient()->getRestClient();
323323
}

src/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function getConfigTreeBuilder(): TreeBuilder
4040
->scalarNode('forced_test_ip')->defaultValue('')->end()
4141
->scalarNode('forced_test_forwarded_ip')->defaultValue('')->end()
4242
->booleanNode('debug_mode')->defaultValue(false)->end()
43+
->booleanNode('disable_prod_log')->defaultValue(false)->end()
4344
->scalarNode('log_directory_path')->end()
4445
->booleanNode('display_errors')->defaultValue(false)->end()
4546
// Bouncer

src/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Constants
2020
public const DEFAULT_LAPI_URL = 'http://localhost:8080';
2121

2222
/** @var string The last version of this library */
23-
public const VERSION = 'v0.27.0';
23+
public const VERSION = 'v0.28.0';
2424

2525
/** @var string The user agent used to send request to LAPI */
2626
public const BASE_USER_AGENT = 'PHP CrowdSec Bouncer/' . self::VERSION;

src/RestClient/ClientAbstract.php renamed to src/RestClient/AbstractClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @copyright Copyright (c) 2020+ CrowdSec
1919
* @license MIT License
2020
*/
21-
abstract class ClientAbstract
21+
abstract class AbstractClient
2222
{
2323
/** @var int|mixed|null */
2424
protected $timeout = null;

src/RestClient/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use CrowdSecBouncer\BouncerException;
1010

11-
class Curl extends ClientAbstract
11+
class Curl extends AbstractClient
1212
{
1313
/**
1414
* Send an HTTP request using cURL and parse its JSON result if any.

src/RestClient/FileGetContents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use CrowdSecBouncer\BouncerException;
88
use Psr\Log\LoggerInterface;
99

10-
class FileGetContents extends ClientAbstract
10+
class FileGetContents extends AbstractClient
1111
{
1212
/** @var string|null */
1313
private $headerString;

0 commit comments

Comments
 (0)