Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7e74ae6b0f | ||
|
c57f7ff2f9 | ||
|
d2a4f06b6a | ||
|
5c801cdb27 | ||
|
d8006be928 | ||
|
7995091b38 | ||
|
8224a1f704 | ||
|
d43ee5a6bd | ||
|
313a1c5c8e | ||
|
eb0d72ffc8 | ||
|
5241eaa11b | ||
|
9f9bf0af6c | ||
|
d65ff46fef | ||
|
5396f8d6de | ||
|
317d46abea | ||
|
994219f47e | ||
|
d757db97a5 | ||
|
4c77f96f24 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
27
README.md
27
README.md
@ -1,20 +1,3 @@
|
||||
<div align="center">
|
||||
|
||||
# Dcat Laravel Log Viewer
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/jqhph/laravel-log-viewer/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-7389D8.svg?style=flat" ></a>
|
||||
<a href="https://styleci.io/repos/215738797">
|
||||
<img src="https://github.styleci.io/repos/215738797/shield" alt="StyleCI">
|
||||
</a>
|
||||
<a href="https://github.com/jqhph/laravel-log-viewer/releases" ><img src="https://img.shields.io/github/release/jqhph/laravel-log-viewer.svg?color=4099DE" /></a>
|
||||
</p>
|
||||
|
||||
`Dcat Log Viewer`是一个`Laravel`日志查看工具,支持大文件日志的查看和搜索功能,更改自[laravel-admin-extensions/log-viewer](https://github.com/laravel-admin-extensions/log-viewer)。
|
||||
|
||||
</div>
|
||||
|
||||

|
||||
|
||||
## 功能
|
||||
|
||||
@ -36,16 +19,16 @@
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
composer require dcat/laravel-log-viewer
|
||||
composer require zyimm/laravel-log-viewer
|
||||
```
|
||||
|
||||
发布配置文件,此步骤可省略
|
||||
|
||||
```bash
|
||||
php artisan vendor:publish --tag=dcat-log-viewer
|
||||
php artisan vendor:publish --tag=zyimm-log-viewer
|
||||
```
|
||||
|
||||
然后访问 `http://hostname/dcat-logs` 即可
|
||||
然后访问 `http://hostname/zyimm-logs` 即可
|
||||
|
||||
配置文件
|
||||
|
||||
@ -54,9 +37,9 @@ php artisan vendor:publish --tag=dcat-log-viewer
|
||||
return [
|
||||
'route' => [
|
||||
// 路由前缀
|
||||
'prefix' => 'dcat-logs',
|
||||
'prefix' => 'zyimm-logs',
|
||||
// 命名空间
|
||||
'namespace' => 'Dcat\LogViewer',
|
||||
'namespace' => 'Zyimm\LogViewer',
|
||||
// 中间件
|
||||
'middleware' => [],
|
||||
],
|
||||
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "dcat/laravel-log-viewer",
|
||||
"name": "zyimm/laravel-log-viewer",
|
||||
"description": "Laravel Log Viewer",
|
||||
"type": "library",
|
||||
"keywords": ["laravel", "log viewer"],
|
||||
"homepage": "https://github.com/jqhph/laravel-log-viewer",
|
||||
"homepage": "http://gogs.zyimm.com/zyimm/laravel-log-viewer",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "jqh",
|
||||
"email": "841324345@qq.com"
|
||||
"name": "zyimm",
|
||||
"email": "zyimm@qq.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
@ -16,13 +16,13 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dcat\\LogViewer\\": "src/"
|
||||
"Zyimm\\LogViewer\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Dcat\\LogViewer\\DcatLogViewerServiceProvider"
|
||||
"Zyimm\\LogViewer\\LogViewerServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
return [
|
||||
'route' => [
|
||||
'prefix' => 'dcat-logs',
|
||||
'namespace' => 'Dcat\LogViewer',
|
||||
'prefix' => 'zyimm-logs',
|
||||
'namespace' => 'Zyimm\LogViewer',
|
||||
'middleware' => [],
|
||||
],
|
||||
|
@ -5,13 +5,12 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Laravel log viewer</title>
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
|
||||
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/html5shiv/r29/html5.min.js"></script>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
<style>
|
||||
body {
|
||||
@ -27,7 +26,7 @@
|
||||
|
||||
h3 {
|
||||
font-weight: 400;
|
||||
font-size: 20px;
|
||||
font-size: 18px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@ -215,7 +214,7 @@
|
||||
}
|
||||
|
||||
.nav>li>a.dir {
|
||||
font-size: 1.1rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
</style>
|
||||
@ -228,37 +227,37 @@
|
||||
|
||||
<div class="col-md-2">
|
||||
<div class="logo">
|
||||
Dcat Log Viewer
|
||||
Zyimm Log Viewer
|
||||
</div>
|
||||
|
||||
<div class="">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title"><i class="fa fa-folder-open-o"></i>
|
||||
<a href="{{ route('dcat-log-viewer') }}">logs</a>
|
||||
<a href="{{ route('zyimm-log-viewer') }}">logs</a>
|
||||
@if($dir)
|
||||
@php($tmp = '')
|
||||
@foreach(explode('/', $dir) as $v)
|
||||
@php($tmp .= '/'.$v)
|
||||
/
|
||||
<a href="{{ route('dcat-log-viewer', ['dir' => trim($tmp, '/')])}}">{{ $v }}</a>
|
||||
<a href="{{ route('zyimm-log-viewer', ['dir' => trim($tmp, '/')])}}">{{ $v }}</a>
|
||||
@endforeach
|
||||
@endif
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<form action="{{ route('dcat-log-viewer') }}" style="display: inline-block;width: 220px;padding-left: 15px">
|
||||
<form action="{{ route('zyimm-log-viewer') }}" style="display: inline-block;width: 220px;padding-left: 15px">
|
||||
<div class="input-group-sm" style="display: inline-block;width: 100%">
|
||||
<input name="filename" class="form-control" value="{{ request('filename') }}" type="text" placeholder="Search..." />
|
||||
<input name="filename" class="form-control" value="{{ app('request')->get('filename') }}" type="text" placeholder="Search..." />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="box-body no-padding">
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
@if(! request('filename'))
|
||||
@if(! app('request')->get('filename'))
|
||||
@foreach($logDirs as $d)
|
||||
<li @if($d === $fileName) class="active" @endif>
|
||||
<a class="dir" href="{{ route('dcat-log-viewer', ['dir' => $d]) }}">
|
||||
<i class="fa fa-folder-o"></i>{{ $d }}
|
||||
<a class="dir" href="{{ route('zyimm-log-viewer', ['dir' => $d]) }}">
|
||||
<i class="fa fa-folder-o"></i>{{ basename($d) }}
|
||||
</a>
|
||||
</li>
|
||||
@endforeach
|
||||
@ -284,18 +283,20 @@
|
||||
<div class="col-md-10">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<a href="{{ route('dcat-log-viewer.download', ['dir' => $dir, 'file' => $fileName]) }}" class="btn btn-primary btn-sm download" style="color: #fff"><i class="fa-download fa"></i> {{ __('Download') }}</a>
|
||||
<a href="{{ route('zyimm-log-viewer.download', ['dir' => $dir, 'file' => $fileName, 'filename' => app('request')->get('filename')]) }}" class="btn btn-primary btn-sm download" style="color: #fff"><i class="fa-download fa"></i> {{ trans('Download') }}</a>
|
||||
|
||||
{{-- <button class="btn btn-default btn-sm download"><i class="fa-trash-o fa"></i> {{ __('Delete') }}</button>--}}
|
||||
{{-- <button class="btn btn-default btn-sm download"><i class="fa-trash-o fa"></i> {{ trans('Delete') }}</button>--}}
|
||||
|
||||
<form style="display: inline-block;width: 180px">
|
||||
<form action="{{ app('request')->fullUrlWithQuery(['keyword' => null,]) }}" style="display: inline-block;width: 180px">
|
||||
<div class="input-group-sm" style="display: inline-block;width: 100%">
|
||||
<input name="keyword" class="form-control" value="{{ request('keyword') }}" type="text" placeholder="Search..." />
|
||||
<input type="hidden" name="dir" value="{{ $dir }}">
|
||||
<input type="hidden" name="filename" value="{{ app('request')->get('filename') }}">
|
||||
<input name="keyword" class="form-control" value="{{ app('request')->get('keyword') }}" type="text" placeholder="Search..." />
|
||||
</div>
|
||||
</form>
|
||||
<div class="float-right">
|
||||
<a class=""><strong>Size:</strong> {{ $size }} <strong>Updated at:</strong>
|
||||
{{ \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s', filectime($filePath)))->diffForHumans() }}</a>
|
||||
{{ date('Y-m-d H:i:s', filectime($filePath)) }}</a>
|
||||
|
||||
<div class="btn-group">
|
||||
@if ($prevUrl)
|
||||
@ -331,7 +332,7 @@
|
||||
@foreach($logs as $index => $log)
|
||||
<tr>
|
||||
<td>{{ $index + 1 }}</td>
|
||||
<td><span class="label bg-{{\Dcat\LogViewer\LogViewer::$levelColors[$log['level']]}}">{{ $log['level'] }}</span></td>
|
||||
<td><span class="label bg-{{\Zyimm\LogViewer\LogViewer::$levelColors[$log['level']]}}">{{ $log['level'] }}</span></td>
|
||||
<td><strong>{{ $log['env'] }}</strong></td>
|
||||
<td style="width:150px;">{{ $log['time'] }}</td>
|
||||
<td><pre>{{ $log['info'] }}</pre></td>
|
||||
@ -386,7 +387,6 @@
|
||||
<!-- jQuery for Bootstrap -->
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
{{--<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>--}}
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
|
||||
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Dcat\LogViewer;
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class DcatLogViewerServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__.'/../resources/view', 'dcat-log-viewer');
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([__DIR__.'/../config' => config_path()], 'dcat-log-viewer');
|
||||
}
|
||||
|
||||
$this->registerRoutes();
|
||||
}
|
||||
|
||||
protected function registerRoutes()
|
||||
{
|
||||
Route::group([
|
||||
'prefix' => config('dcat-log-viewer.route.prefix', 'dcat-logs'),
|
||||
'namespace' => config('dcat-log-viewer.route.namespace', 'Dcat\LogViewer'),
|
||||
'middleware' => config('dcat-log-viewer.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->get('/', 'LogController@index')->name('dcat-log-viewer');
|
||||
$router->get('{file}', 'LogController@index')->name('dcat-log-viewer.file');
|
||||
$router->get('download/{file}', 'LogController@download')->name('dcat-log-viewer.download');
|
||||
});
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Dcat\LogViewer;
|
||||
namespace Zyimm\LogViewer;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@ -8,18 +8,20 @@ class LogController
|
||||
{
|
||||
public function index($file = null)
|
||||
{
|
||||
$dir = trim(request('dir'));
|
||||
$filename = trim(request('filename'));
|
||||
$offset = request('offset');
|
||||
$keyword = trim(request('keyword'));
|
||||
$lines = $keyword ? (config('dcat-log-viewer.search_page_items') ?: 500) : (config('dcat-log-viewer.page_items') ?: 30);
|
||||
$request = app('request');
|
||||
|
||||
$dir = trim($request->get('dir'));
|
||||
$filename = trim($request->get('filename'));
|
||||
$offset = $request->get('offset');
|
||||
$keyword = trim($request->get('keyword'));
|
||||
$lines = $keyword ? (config('zyimm-log-viewer.search_page_items') ?: 500) : (config('zyimm-log-viewer.page_items') ?: 30);
|
||||
|
||||
$viewer = new LogViewer($this->getDirectory(), $dir, $file);
|
||||
|
||||
$viewer->setKeyword($keyword);
|
||||
$viewer->setFilename($filename);
|
||||
|
||||
return view('dcat-log-viewer::log', [
|
||||
return view('zyimm-log-viewer::log', [
|
||||
'dir' => $dir,
|
||||
'logs' => $viewer->fetch($offset, $lines),
|
||||
'logFiles' => $this->formatLogFiles($viewer, $dir),
|
||||
@ -33,16 +35,26 @@ class LogController
|
||||
]);
|
||||
}
|
||||
|
||||
public function download($file = null)
|
||||
public function download()
|
||||
{
|
||||
$viewer = new LogViewer($this->getDirectory(), request('dir'), $file);
|
||||
$request = app('request');
|
||||
|
||||
$file = trim($request->get('file'));
|
||||
$dir = trim($request->get('dir'));
|
||||
$filename = trim($request->get('filename'));
|
||||
$keyword = trim($request->get('keyword'));
|
||||
|
||||
$viewer = new LogViewer($this->getDirectory(), $dir, $file);
|
||||
|
||||
$viewer->setKeyword($keyword);
|
||||
$viewer->setFilename($filename);
|
||||
|
||||
return response()->download($viewer->getFilePath());
|
||||
}
|
||||
|
||||
protected function getDirectory()
|
||||
{
|
||||
return config('dcat-log-viewer.directory') ?: storage_path('logs');
|
||||
return config('zyimm-log-viewer.directory') ?: storage_path('logs');
|
||||
}
|
||||
|
||||
protected function formatLogFiles(LogViewer $logViewer, $currentDir)
|
||||
@ -61,7 +73,7 @@ class LogController
|
||||
|
||||
return [
|
||||
'file' => $value,
|
||||
'url' => route('dcat-log-viewer.file', ['file' => $file, 'dir' => $dir]),
|
||||
'url' => route('zyimm-log-viewer.file', ['file' => $file, 'dir' => $dir]),
|
||||
'active' => $logViewer->isCurrentFile($value),
|
||||
];
|
||||
}, $logViewer->getLogFiles());
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Dcat\LogViewer;
|
||||
namespace Zyimm\LogViewer;
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
@ -73,12 +73,38 @@ class LogViewer
|
||||
*/
|
||||
public function __construct($basePath, $dir, $file = null)
|
||||
{
|
||||
$this->basePath = rtrim($basePath, '/');
|
||||
$this->currentDirectory = rtrim($dir, '/');
|
||||
$this->file = $file;
|
||||
$this->basePath = $this->getRealPath(rtrim($basePath, '/'));
|
||||
$this->currentDirectory = $this->formatPath(rtrim($dir, '/'));
|
||||
$this->file = $this->formatPath($file);
|
||||
$this->files = new Filesystem();
|
||||
}
|
||||
|
||||
protected function getRealPath($path)
|
||||
{
|
||||
try {
|
||||
$paths = explode('/', $path);
|
||||
|
||||
$result = '';
|
||||
foreach ($paths as $v) {
|
||||
$result .= $v.'/';
|
||||
|
||||
$current = rtrim($result, '/');
|
||||
if (is_link($current)) {
|
||||
$result = readlink($current).'/';
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim($result, '/');
|
||||
} catch (\Throwable $e) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatPath($path)
|
||||
{
|
||||
return str_replace(['../'], '', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file path by giving log file name.
|
||||
*
|
||||
@ -98,12 +124,12 @@ class LogViewer
|
||||
|
||||
public function setKeyword($value)
|
||||
{
|
||||
$this->keyword = $value;
|
||||
$this->keyword = strtolower($value);
|
||||
}
|
||||
|
||||
public function setFilename($value)
|
||||
{
|
||||
$this->filename = $value;
|
||||
$this->filename = $this->formatPath($value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,10 +162,10 @@ class LogViewer
|
||||
}
|
||||
|
||||
$files = glob($this->mergeDirectory().'/*.*');
|
||||
$files = array_combine($files, array_map('filemtime', $files));
|
||||
arsort($files);
|
||||
//$files = array_combine($files, array_map('filemtime', $files));
|
||||
rsort($files);
|
||||
|
||||
return array_map('basename', array_keys($files));
|
||||
return array_map('basename', $files);
|
||||
}
|
||||
|
||||
public function getLogDirectories()
|
||||
@ -160,7 +186,7 @@ class LogViewer
|
||||
return $this->getLogBasePath();
|
||||
}
|
||||
|
||||
return $this->getLogBasePath() . '/' . $this->currentDirectory;
|
||||
return $this->getLogBasePath().'/'.$this->currentDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,10 +236,12 @@ class LogViewer
|
||||
return false;
|
||||
}
|
||||
|
||||
return route('dcat-log-viewer.file', [
|
||||
return route('zyimm-log-viewer.file', [
|
||||
'file' => $this->getFile(),
|
||||
'offset' => $this->pageOffset['end'],
|
||||
'keyword' => $this->keyword,
|
||||
'dir' => $this->currentDirectory,
|
||||
'filename' => $this->filename,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -232,10 +260,12 @@ class LogViewer
|
||||
return false;
|
||||
}
|
||||
|
||||
return route('dcat-log-viewer.file', [
|
||||
return route('zyimm-log-viewer.file', [
|
||||
'file' => $this->getFile(),
|
||||
'offset' => -$this->pageOffset['start'],
|
||||
'keyword' => $this->keyword,
|
||||
'dir' => $this->currentDirectory,
|
||||
'filename' => $this->filename,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -261,7 +291,7 @@ class LogViewer
|
||||
$result = [];
|
||||
|
||||
foreach ($logs as $log) {
|
||||
if (Str::contains(implode(' ', $log), $this->keyword)) {
|
||||
if (Str::contains(strtolower(implode(' ', $log)), $this->keyword)) {
|
||||
$result[] = $log;
|
||||
}
|
||||
}
|
||||
|
32
src/LogViewerServiceProvider.php
Normal file
32
src/LogViewerServiceProvider.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Zyimm\LogViewer;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class LogViewerServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__.'/../resources/view', 'zyimm-log-viewer');
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([__DIR__.'/../config' => config_path()], 'zyimm-log-viewer');
|
||||
}
|
||||
|
||||
$this->registerRoutes();
|
||||
}
|
||||
|
||||
protected function registerRoutes()
|
||||
{
|
||||
app('router')->group([
|
||||
'prefix' => config('zyimm-log-viewer.route.prefix', 'zyimm-logs'),
|
||||
'namespace' => config('zyimm-log-viewer.route.namespace', 'Zyimm\LogViewer'),
|
||||
'middleware' => config('zyimm-log-viewer.route.middleware'),
|
||||
], function ($router) {
|
||||
$router->get('/', ['as' => 'zyimm-log-viewer', 'uses' => 'LogController@index',]);
|
||||
$router->get('download', ['as' => 'zyimm-log-viewer.download', 'uses' => 'LogController@download',]);
|
||||
$router->get('{file}', ['as' => 'zyimm-log-viewer.file', 'uses' => 'LogController@index',]);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user