Skip to content

Commit fc23e94

Browse files
authored
Merge pull request #8 from crowdsecurity/log-path
log path
2 parents 84c4bc9 + 775035a commit fc23e94

File tree

7 files changed

+24
-92
lines changed

7 files changed

+24
-92
lines changed

docs/contribute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ docker-compose run wordpress<X.X> bash
135135
### Display the plugin logs
136136

137137
```bash
138-
tail -f logs/*
138+
tail -f logs/debug-*
139139
```
140140

141141
#### New feature workflow

inc/bouncer-instance.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use CrowdSecBouncer\Bouncer;
44
use CrowdSecBouncer\BouncerException;
55
use CrowdSecBouncer\Constants;
6+
use Monolog\Formatter\LineFormatter;
67
use Monolog\Handler\RotatingFileHandler;
78
use Monolog\Logger;
89
use Symfony\Component\Cache\Adapter\AbstractAdapter;
@@ -25,15 +26,18 @@ function getCrowdSecLoggerInstance(): Logger
2526

2627
// Log more data if WP_DEBUG=1
2728

28-
$loggerLevel = WP_DEBUG ? Logger::DEBUG : Logger::INFO;
2929
$logger = new Logger('wp_bouncer');
30-
$fileHandler = new RotatingFileHandler(CROWDSEC_LOG_PATH, 0, $loggerLevel);
3130

32-
// Set custom readble logger for WP_DEBUG=1
31+
$fileHandler = new RotatingFileHandler(CROWDSEC_LOG_PATH, 0, Logger::INFO);
32+
$fileHandler->setFormatter(new LineFormatter("%datetime%|%level%|%context%\n"));
33+
$logger->pushHandler($fileHandler);
34+
35+
// Set custom readable logger for WP_DEBUG=1
3336
if (WP_DEBUG) {
34-
$fileHandler->setFormatter(new \Bramus\Monolog\Formatter\ColoredLineFormatter(null, "[%datetime%] %message% %context%\n", 'H:i:s'));
37+
$debugFileHandler = new RotatingFileHandler(CROWDSEC_DEBUG_LOG_PATH, 0, Logger::DEBUG);
38+
$debugFileHandler->setFormatter(new \Bramus\Monolog\Formatter\ColoredLineFormatter(null, "[%datetime%] %message% %context%\n", 'H:i:s'));
39+
$logger->pushHandler($debugFileHandler);
3540
}
36-
$logger->pushHandler($fileHandler);
3741

3842
return $logger;
3943
}

inc/constants.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
define('CROWDSEC_LOG_PATH', CROWDSEC_PLUGIN_PATH.'/logs/crowdsec.log');
3+
$crowdsecRandomLogFolder = get_option('crowdsec_random_log_folder') ?: '';
4+
define('CROWDSEC_LOG_PATH', CROWDSEC_PLUGIN_PATH."/logs/$crowdsecRandomLogFolder/prod.log");
5+
define('CROWDSEC_DEBUG_LOG_PATH', CROWDSEC_PLUGIN_PATH."/logs/$crowdsecRandomLogFolder/debug.log");
46
define('CROWDSEC_CACHE_PATH', CROWDSEC_PLUGIN_PATH.'/.cache');
57

68
define('CROWDSEC_BOUNCING_LEVEL_DISABLED', 'bouncing_disabled');

inc/plugin-setup.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function activate_crowdsec_plugin()
3131
update_option('crowdsec_hide_mentions', false);
3232
update_option('crowdsec_trust_ip_forward', '');
3333
update_option('crowdsec_trust_ip_forward_array', []);
34+
35+
if (!get_option('crowdsec_random_log_folder')) {
36+
update_option('crowdsec_random_log_folder', bin2hex(random_bytes(64)));
37+
}
3438
}
3539

3640
/**

inc/templates/dashboard.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

logs/index.php

Whitespace-only changes.

tests/functional/__tests__/functional.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ const WORDPRESS_VERSION = process.env.WORDPRESS_VERSION;
88
const ADMIN_LOGIN = "admin";
99
const ADMIN_PASSWORD = "my_very_very_secret_admin_password";
1010
const LAPI_URL = process.env.LAPI_URL_FROM_CONTAINERS;
11-
const NOTIFY = !!process.env.DEBUG;
11+
const DEBUG = !!process.env.DEBUG;
1212
const TIMEOUT = (!!process.env.DEBUG ? 5 * 60 : 8) * 1000;
1313
const OTHER_IP = "1.2.3.4";
1414
const adminUrl = `${BASE_URL}/wp-admin/`;
1515

1616
const notify = (message) => {
17-
if (NOTIFY) {
17+
if (DEBUG) {
1818
notifier.notify({
1919
title: "CrowdSec automation",
2020
message: message,
@@ -33,10 +33,6 @@ const WP56 = WORDPRESS_VERSION === "";
3333
const WP55 = WORDPRESS_VERSION === "5.5";
3434
const WP54 = WORDPRESS_VERSION === "5.4";
3535
const WP53 = WORDPRESS_VERSION === "5.3";
36-
const WP52 = WORDPRESS_VERSION === "5.2";
37-
const WP51 = WORDPRESS_VERSION === "5.1";
38-
const WP50 = WORDPRESS_VERSION === "5.0";
39-
const WP49 = WORDPRESS_VERSION === "4.9";
4036

4137
const waitForNavigation = page.waitForNavigation();
4238

@@ -266,7 +262,7 @@ const remediationShouldUpdate = async (
266262

267263
describe(`Setup WordPress ${WORDPRESS_VERSION} and CrowdSec plugin`, () => {
268264

269-
beforeEach(() => console.log(expect.getState().currentTestName));
265+
beforeEach(() => (DEBUG ? console.log(expect.getState().currentTestName) : null))
270266

271267
it('Should install wordpress"', async () => {
272268
notify(`Setup WordPress ${WORDPRESS_VERSION} and CrowdSec plugin`);
@@ -328,7 +324,7 @@ const remediationShouldUpdate = async (
328324

329325
describe(`Run in Live mode`, () => {
330326

331-
beforeEach(() => console.log(expect.getState().currentTestName));
327+
beforeEach(() => (DEBUG ? console.log(expect.getState().currentTestName) : null))
332328

333329
it('Should reduce the cache durations"', async () => {
334330
notify("Run in Live mode");
@@ -493,7 +489,7 @@ describe(`Run in Live mode`, () => {
493489

494490
describe(`Run in Stream mode`, () => {
495491

496-
beforeEach(() => console.log(expect.getState().currentTestName));
492+
beforeEach(() => (DEBUG ? console.log(expect.getState().currentTestName) : null))
497493

498494
it('Should enable the stream mode"', async () => {
499495
notify("Run in Stream mode");
@@ -534,7 +530,7 @@ describe(`Run in Stream mode`, () => {
534530

535531
describe(`Use Redis technology`, () => {
536532

537-
beforeEach(() => console.log(expect.getState().currentTestName));
533+
beforeEach(() => (DEBUG ? console.log(expect.getState().currentTestName) : null))
538534

539535
it('Should be able to use Redis cache"', async () => {
540536
notify("Use Redis technology");
@@ -565,7 +561,7 @@ describe(`Use Redis technology`, () => {
565561

566562
describe(`Use Memcached technology`, () => {
567563

568-
beforeEach(() => console.log(expect.getState().currentTestName));
564+
beforeEach(() => (DEBUG ? console.log(expect.getState().currentTestName) : null))
569565

570566
it('Should be able to use Memcached cache"', async () => {
571567
notify("Use Memcached technology");

0 commit comments

Comments
 (0)