Skip to content

Commit 9cd7991

Browse files
authored
Merge pull request #5 from zunnu/4.x-dev
4.x dev
2 parents 288a2b4 + fae1ef0 commit 9cd7991

File tree

16 files changed

+177
-59
lines changed

16 files changed

+177
-59
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/composer.lock
2+
/composer.phar
23
/phpunit.xml
3-
/vendor
4-
config/Migrations/schema-dump-default.lock
4+
/.phpunit.result.cache
5+
/phpunit.phar
6+
/config/Migrations/schema-dump-default.lock
7+
/vendor/
8+
/.idea/

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# LogReader plugin for CakePHP
22

3-
A simple CakePHP log reader.
3+
Log reader helps you quickly and clearly see individual log entries of your cakePHP application.
4+
With log reader you no longer need to read raw log files from the server. Log reader allows you to read logs straight from the UI.
5+
6+
Log readers API allows you to create your own custom application to help you get head of errors and provide you with useful information.
7+
8+
## Documentation
9+
See the API documentation of [Log Reader](https://github.com/zunnu/log-reader/wiki)
410

511
## Requirements
6-
* CakePHP 3.x
12+
* CakePHP 4.x
713
* PHP 7.2 >
814

915
## Installing Using [Composer][composer]
@@ -25,9 +31,6 @@ You can see the logs by going to
2531
http://app-address/log-reader
2632
<img src="https://i.imgur.com/8sCwLBh.png" alt="logs">
2733

28-
## Documentation
29-
See the API documentation of [Log Reader](https://github.com/zunnu/log-reader/wiki)
30-
3134
## License
3235

3336
Licensed under [The MIT License][mit].

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"type": "cakephp-plugin",
55
"license": "MIT",
66
"require": {
7-
"cakephp/cakephp": "^3.5"
7+
"php": ">=7.2",
8+
"cakephp/cakephp": "^4.0"
89
},
910
"require-dev": {
10-
"phpunit/phpunit": "^5.7.14|^6.0"
11+
"phpunit/phpunit": "^8.5 || ^9.3"
1112
},
1213
"autoload": {
1314
"psr-4": {

config/routes.php

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

phpunit.xml.dist

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@
1717
</testsuite>
1818
</testsuites>
1919

20-
<!-- Setup a listener for fixtures -->
21-
<listeners>
22-
<listener class="Cake\TestSuite\Fixture\FixtureInjector">
23-
<arguments>
24-
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
25-
</arguments>
26-
</listener>
27-
</listeners>
20+
<!-- Setup fixture extension -->
21+
<extensions>
22+
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension" />
23+
</extensions>
2824

2925
<filter>
3026
<whitelist>
3127
<directory suffix=".php">src/</directory>
3228
</whitelist>
3329
</filter>
34-
3530
</phpunit>

src/Controller/Api/V1/AppController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace LogReader\Controller\Api\V1;
45

src/Controller/Api/V1/LogReaderController.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace LogReader\Controller\Api\V1;
35

46
use LogReader\Controller\Api\V1\AppController;
@@ -7,15 +9,23 @@
79

810
class LogReaderController extends AppController
911
{
10-
public function initialize() {
12+
/**
13+
* initialize method
14+
*
15+
* @return void
16+
*/
17+
public function initialize(): void
18+
{
1119
parent::initialize();
20+
$this->RequestHandler->renderAs($this, 'json');
1221
}
1322

1423
/**
1524
* Logs method
1625
*/
17-
public function logs($date = null) {
18-
$this->viewBuilder()->setLayout(false);
26+
public function logs($date = null)
27+
{
28+
$this->viewBuilder()->disableAutoLayout();
1929
$conditions = [];
2030

2131
// SEARCH
@@ -31,6 +41,8 @@ public function logs($date = null) {
3141
$types = explode(',', $data['types']);
3242
$conditions['types'] = array_map('trim', array_filter($types));
3343
}
44+
} elseif ($this->request->is('get')) {
45+
$conditions['files'] = ['error.log', 'debug.log'];
3446
}
3547

3648
$this->Reader = new Reader($conditions);
@@ -46,8 +58,9 @@ public function logs($date = null) {
4658
* Types method
4759
* Return available log types
4860
*/
49-
public function types($date = null) {
50-
$this->viewBuilder()->setLayout(false);
61+
public function types($date = null)
62+
{
63+
$this->viewBuilder()->disableAutoLayout();
5164
$this->Reader = new Reader();
5265
$types = $this->Reader->getLogTypes();
5366

@@ -61,8 +74,9 @@ public function types($date = null) {
6174
* Files method
6275
* Return the available log files
6376
*/
64-
public function files($date = null) {
65-
$this->viewBuilder()->setLayout(false);
77+
public function files($date = null)
78+
{
79+
$this->viewBuilder()->disableAutoLayout();
6680
$this->Reader = new Reader();
6781
$files = $this->Reader->getFiles();
6882

src/Controller/AppController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace LogReader\Controller;
45

src/Controller/LogReaderController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace LogReader\Controller;
35

46
use LogReader\Controller\AppController;
@@ -12,15 +14,17 @@ class LogReaderController extends AppController
1214
*
1315
* @return void
1416
*/
15-
public function initialize() {
17+
public function initialize(): void
18+
{
1619
parent::initialize();
1720
}
1821

1922
/**
2023
* Index method
2124
*/
22-
public function index($date = null) {
23-
$this->viewBuilder()->setLayout(false);
25+
public function index($date = null)
26+
{
27+
$this->viewBuilder()->disableAutoLayout();
2428
$conditions = [];
2529

2630
// SEARCH

src/Plugin.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,102 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace LogReader;
45

56
use Cake\Core\BasePlugin;
7+
use Cake\Core\ContainerInterface;
8+
use Cake\Core\PluginApplicationInterface;
9+
use Cake\Http\MiddlewareQueue;
10+
use Cake\Routing\RouteBuilder;
11+
use Cake\Console\CommandCollection;
612

713
/**
814
* Plugin for LogReader
915
*/
1016
class Plugin extends BasePlugin
1117
{
18+
/**
19+
* Load all the plugin configuration and bootstrap logic.
20+
*
21+
* The host application is provided as an argument. This allows you to load
22+
* additional plugin dependencies, or attach events.
23+
*
24+
* @param \Cake\Core\PluginApplicationInterface $app The host application
25+
* @return void
26+
*/
27+
public function bootstrap(PluginApplicationInterface $app): void
28+
{
29+
}
30+
31+
/**
32+
* Add routes for the plugin.
33+
*
34+
* If your plugin has many routes and you would like to isolate them into a separate file,
35+
* you can create `$plugin/config/routes.php` and delete this method.
36+
*
37+
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
38+
* @return void
39+
*/
40+
public function routes(RouteBuilder $routes): void
41+
{
42+
$routes->plugin(
43+
'LogReader',
44+
['path' => '/log-reader'],
45+
function (RouteBuilder $builder) {
46+
$builder->connect('/', ['controller' => 'LogReader', 'action' => 'index'])->setExtensions(['json']);
47+
48+
$builder->prefix('api', function (RouteBuilder $builder) {
49+
$builder->prefix('v1', function (RouteBuilder $builder) {
50+
$builder->connect('/files', ['controller' => 'LogReader', 'action' => 'files'])->setExtensions(['json']);
51+
$builder->connect('/types', ['controller' => 'LogReader', 'action' => 'types'])->setExtensions(['json']);
52+
$builder->connect('/logs', ['controller' => 'LogReader', 'action' => 'logs'])->setExtensions(['json']);
53+
// // $builder->connect('/:controller');
54+
});
55+
});
56+
57+
$builder->fallbacks();
58+
}
59+
);
60+
parent::routes($routes);
61+
}
62+
63+
/**
64+
* Add middleware for the plugin.
65+
*
66+
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
67+
* @return \Cake\Http\MiddlewareQueue
68+
*/
69+
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
70+
{
71+
// Add your middlewares here
72+
73+
return $middlewareQueue;
74+
}
75+
76+
/**
77+
* Add commands for the plugin.
78+
*
79+
* @param \Cake\Console\CommandCollection $commands The command collection to update.
80+
* @return \Cake\Console\CommandCollection
81+
*/
82+
public function console(CommandCollection $commands) : CommandCollection
83+
{
84+
// Add your commands here
85+
86+
$commands = parent::console($commands);
87+
88+
return $commands;
89+
}
90+
91+
/**
92+
* Register application container services.
93+
*
94+
* @param \Cake\Core\ContainerInterface $container The Container to update.
95+
* @return void
96+
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
97+
*/
98+
public function services(ContainerInterface $container): void
99+
{
100+
// Add your services here
101+
}
12102
}

0 commit comments

Comments
 (0)