Compare commits

...

11 Commits

Author SHA1 Message Date
zhouyangyang
7e74ae6b0f namespace 2020-11-26 14:09:57 +08:00
zhouyangyang
c57f7ff2f9 namespace 2020-11-26 14:02:44 +08:00
zhouyangyang
d2a4f06b6a title 2020-11-25 13:33:50 +08:00
zhouyangyang
5c801cdb27 忽略 2020-11-25 11:42:34 +08:00
zhouyangyang
d8006be928 忽略 2020-11-25 11:37:43 +08:00
zhouyangyang
7995091b38 md 2020-11-25 11:34:31 +08:00
zhouyangyang
8224a1f704 cdn 2020-11-25 11:28:00 +08:00
zhouyangyang
d43ee5a6bd cdn 2020-11-25 11:21:51 +08:00
Jiang Qinghua
313a1c5c8e
Update LogViewer.php 2020-07-14 22:45:27 +08:00
jqh
eb0d72ffc8 wip 2020-07-14 16:32:35 +08:00
jqh
5241eaa11b wip 2020-07-14 11:26:40 +08:00
9 changed files with 86 additions and 100 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -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>
![](https://cdn.learnku.com/uploads/images/202007/09/38389/5Ps3bfhdrR.png!large)
## 功能
@ -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' => [],
],

View File

@ -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"
]
}
}

View File

@ -2,8 +2,8 @@
return [
'route' => [
'prefix' => 'dcat-logs',
'namespace' => 'Dcat\LogViewer',
'prefix' => 'zyimm-logs',
'namespace' => 'Zyimm\LogViewer',
'middleware' => [],
],

View File

@ -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,25 +227,25 @@
<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="{{ app('request')->get('filename') }}" type="text" placeholder="Search..." />
</div>
@ -257,8 +256,8 @@
@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,9 +283,9 @@
<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, 'filename' => app('request')->get('filename')]) }}" class="btn btn-primary btn-sm download" style="color: #fff"><i class="fa-download fa"></i> {{ trans('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> {{ trans('Delete') }}</button>--}}
{{-- <button class="btn btn-default btn-sm download"><i class="fa-trash-o fa"></i> {{ trans('Delete') }}</button>--}}
&nbsp;
<form action="{{ app('request')->fullUrlWithQuery(['keyword' => null,]) }}" style="display: inline-block;width: 180px">
<div class="input-group-sm" style="display: inline-block;width: 100%">
@ -297,7 +296,7 @@
</form>
<div class="float-right">
<a class=""><strong>Size:</strong> {{ $size }} &nbsp; <strong>Updated at:</strong>
{{ date('Y-m-d H:i:s', filectime($filePath)) }}</a>
{{ date('Y-m-d H:i:s', filectime($filePath)) }}</a>
&nbsp;
<div class="btn-group">
@if ($prevUrl)
@ -333,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>
@ -388,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>

View File

@ -1,32 +0,0 @@
<?php
namespace Dcat\LogViewer;
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()
{
app('router')->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->get('/', ['as' => 'dcat-log-viewer', 'uses' => 'LogController@index',]);
$router->get('download', ['as' => 'dcat-log-viewer.download', 'uses' => 'LogController@download',]);
$router->get('{file}', ['as' => 'dcat-log-viewer.file', 'uses' => 'LogController@index',]);
});
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Dcat\LogViewer;
namespace Zyimm\LogViewer;
use Illuminate\Support\Str;
@ -14,14 +14,14 @@ class LogController
$filename = trim($request->get('filename'));
$offset = $request->get('offset');
$keyword = trim($request->get('keyword'));
$lines = $keyword ? (config('dcat-log-viewer.search_page_items') ?: 500) : (config('dcat-log-viewer.page_items') ?: 30);
$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),
@ -54,7 +54,7 @@ class LogController
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)
@ -73,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());

View File

@ -1,6 +1,6 @@
<?php
namespace Dcat\LogViewer;
namespace Zyimm\LogViewer;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
@ -81,19 +81,23 @@ class LogViewer
protected function getRealPath($path)
{
$paths = explode('/', $path);
try {
$paths = explode('/', $path);
$result = '';
foreach ($paths as $v) {
$result .= $v.'/';
$result = '';
foreach ($paths as $v) {
$result .= $v.'/';
$current = rtrim($result, '/');
if (is_link($current)) {
$result = readlink($current).'/';
$current = rtrim($result, '/');
if (is_link($current)) {
$result = readlink($current).'/';
}
}
}
return rtrim($result, '/');
return rtrim($result, '/');
} catch (\Throwable $e) {
return $path;
}
}
protected function formatPath($path)
@ -158,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()
@ -232,7 +236,7 @@ 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,
@ -256,7 +260,7 @@ 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,

View 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',]);
});
}
}