Skip to content

Commit

Permalink
Integrated Aryeh’s Logbook. More prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin Dalzell authored and Erin Dalzell committed Dec 12, 2017
1 parent e2f8736 commit f2b101d
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 50 deletions.
3 changes: 3 additions & 0 deletions PowerTools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea
Thumbs.db
63 changes: 34 additions & 29 deletions PowerTools/PowerToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace Statamic\Addons\PowerTools;

use Log;
use Statamic\API\Arr;
use Statamic\API\File;
use Statamic\API\Path;
use Statamic\API\Cache;
use Statamic\API\Search;
use Statamic\API\Stache;
use Statamic\Extend\Controller;
use Monolog\Handler\StreamHandler;
use Illuminate\Support\Facades\Artisan;
use Rap2hpoutre\LaravelLogViewer\LaravelLogViewer;


class PowerToolsController extends Controller
{
Expand All @@ -22,40 +21,46 @@ public function phpinfo()
return $this->view('phpinfo', ['html' => $this->getPHPInfo()]);
}

public function log()

public function logs()
{
$this->authorize('super');
if (! auth()->check()) {
return redirect('/');
}

return $this->view('log', ['html' => $this->getLog()]);
}
if ($file = request('log')) {
LaravelLogViewer::setFile(base64_decode($file));
}

/**
* Returns the logs
*
* @return string
*/
public function getLog()
{
$log = '';

$handler = Arr::first(Log::getMonolog()->getHandlers(), function ($key, $handler) {
return $handler instanceof StreamHandler;
});

if ($handler) {
$log = collect(
explode("\n", File::get($handler->getUrl()))
)->map(function ($line) {
return $this->highlight($line);
})->implode("\n");
if ($file = request('dl')) {
return response()->download(LaravelLogViewer::pathToLogFile(base64_decode($file)));
}

return $log;
}
if ($file = request('del')) {
app('files')->delete(LaravelLogViewer::pathToLogFile(base64_decode($file)));

return redirect(request()->url());
}

if (request()->has('delall')) {
foreach (LaravelLogViewer::getFiles(true) as $file) {
app('files')->delete(LaravelLogViewer::pathToLogFile($file));
}

/**
return redirect(request()->url());
}

$data = [
'logs' => LaravelLogViewer::all(),
'files' => LaravelLogViewer::getFiles(true),
'current_file' => LaravelLogViewer::getFileName(),
'action_path' => route('logs'),
];

return $this->view('logs', $data);
}

/**
* Returns the PHP Info
*
* @return string
Expand Down
6 changes: 4 additions & 2 deletions PowerTools/PowerToolsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class PowerToolsListener extends Listener
*/
public function powerUp()
{
return $this->css->tag('powertools.css');
$html = $this->js->tag('powertools');
$html .= $this->css->tag('powertools');
return $html;
}

/**
Expand All @@ -44,7 +46,7 @@ public function nav($nav)
Nav::item('PHP Info')->route('phpinfo')->icon('info'));
$nav->addTo(
'tools',
Nav::item('Log')->route('log')->icon('flashlight'));
Nav::item('Logs')->route('logs')->icon('book'));
}
}
}
6 changes: 6 additions & 0 deletions PowerTools/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "edalzell/powertools",
"require": {
"rap2hpoutre/laravel-log-viewer": "*"
}
}
2 changes: 1 addition & 1 deletion PowerTools/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: PowerTools
version: 1.3
version: 1.4
description: Rebuild your search index, cache & asset presets, see your PHP Info and your log
url: https://github.com/edalzell/statamic-powertools
developer: Erin Dalzell
Expand Down
22 changes: 22 additions & 0 deletions PowerTools/resources/assets/css/powertools.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,25 @@
width: 95vw;
}
}

#logbook .log-picker { display: inline-block; }

#logbook .dossier { margin-top: 0; }
#logbook .dossier td { vertical-align: top; }
#logbook .dossier .level { min-width: 80px; }
#logbook .dossier .context { min-width: 80px; }
#logbook .dossier .date { min-width: 180px; }
#logbook .dossier .text { word-break: break-all; }

#logbook .dossier .expandable { cursor: zoom-in; }
#logbook .dossier .expandable.open { cursor: zoom-out; }

#logbook .stack-trace {
white-space: pre-wrap;
font-size: 0.9em;
}

#logbook .level-icon::before {
font-family: entypo;
font-size: 13px;
}
16 changes: 16 additions & 0 deletions PowerTools/resources/assets/js/powertools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
document.addEventListener('DOMContentLoaded', function(e) {

$('#logbook .log-picker').on('change', function () {
$(this).submit();
});

$('#logbook .dossier .expandable').click(function() {
$(this).toggleClass('open');
$('#' + $(this).data('display')).toggle();
});

$('#delete-log, #delete-all-log').click(function() {
return confirm('Are you sure?');
});

});
4 changes: 3 additions & 1 deletion PowerTools/resources/lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
'php_path' => 'Path to PHP',
'php_path_instruct' => "The path to PHP on your system, used to create asset presets in the background.",
'shell_path' => 'Your Shell Path',
'shell_path_instruct' => "The path to the shell on your system system, used to create asset presets in the background."
'shell_path_instruct' => "The path to the shell on your system system, used to create asset presets in the background.",
'hide_nav' => 'Hide Logbook from Nav',
'hide_nav_instruct' => 'This hides the nav item from other CP users while still keeping Logbook accessible directly via `/cp/addons/logbook`.',
];
14 changes: 0 additions & 14 deletions PowerTools/resources/views/log.blade.php

This file was deleted.

93 changes: 93 additions & 0 deletions PowerTools/resources/views/logs.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@extends('layout')

@section('content')
<div id="logbook">

<div class="card sticky flat-bottom">
<div class="head">
<h1>Logbook</h1>
</div>
</div>

@if (count($files))
<div class="card flat-top flat-bottom">
<form class="log-picker" method="GET" action="{{ $action_path }}">
<div class="select" data-content="@if($current_file) {{ $current_file }} @endif">
<select name="log">
@foreach($files as $file)
<option value="{{ base64_encode($file) }}" @if ($file == $current_file) selected @endif>{{ $file }}</option>
@endforeach
</select>
</div>
</form>

@if ($current_file)
<div class="pull-right">
@if (count($logs))
<a id="download-log" class="btn btn-primary" href="?dl={{ base64_encode($current_file) }}">Download file</a>
@endif

@if (count($files) > 1)
<div class="btn-group">
<a id="delete-log" class="btn btn-danger" href="?del={{ base64_encode($current_file) }}">Delete file</a>
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a id="delete-all-log" href="?delall=true">Delete all files</a></li>
</ul>
</div>
@else
<a id="delete-log" class="btn btn-danger" href="?del={{ base64_encode($current_file) }}">Delete file</a>
@endif
</div>
@endif
</div>
@endif

<div class="card flat-top">
@if (count($logs) === 0)
Log file is empty.
@elseif ($logs === null)
Log file >50M, please download it.
@else
<table class="dossier">
<thead>
<tr>
<th>Level</th>
<th>Context</th>
<th>Date</th>
<th>Content</th>
</tr>
</thead>
<tbody>
@foreach ($logs as $key => $log)
<tr class="@if ($log['stack']) expandable @endif" data-display="stack{{{$key}}}">
<td class="level">
<span class="level-icon icon-{{{ $log['level_img'] }}}" aria-hidden="true"></span>
&nbsp;{{ $log['level'] }}
</td>
<td class="context">
{{ $log['context'] }}
</td>
<td class="date">
{{{ $log['date'] }}}
</td>
<td class="text">
{{{ $log['text'] }}}

@if (isset($log['in_file'])) <br>{{{ $log['in_file'] }}} @endif

@if ($log['stack'])
<div id="stack{{{ $key }}}" class="stack-trace" style="display: none;">{{{ trim($log['stack']) }}}</div>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>

</div>
@endsection
6 changes: 3 additions & 3 deletions PowerTools/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ routes:
uses: phpinfo
as: phpinfo

/log:
uses: log
as: log
/logs:
uses: logs
as: logs

/rebuild-search:
uses: rebuildSearchIndex
Expand Down

0 comments on commit f2b101d

Please sign in to comment.