Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
media-resource
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨昕
media-resource
Commits
b9a6f17b
Commit
b9a6f17b
authored
Jul 20, 2020
by
杨昕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加日志
parent
e62661fa
Pipeline
#9965
passed with stages
in 36 seconds
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
396 additions
and
0 deletions
+396
-0
UsersController.php
app/Http/Controllers/Api/Client/UsersController.php
+3
-0
LogModel.php
app/Model/LogModel.php
+46
-0
AppServiceProvider.php
app/Providers/AppServiceProvider.php
+1
-0
Log.php
app/Tool/Log.php
+346
-0
No files found.
app/Http/Controllers/Api/Client/UsersController.php
View file @
b9a6f17b
...
...
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\Client;
use
App\Exceptions\ControllerException
;
use
App\Exceptions\DatabaseException
;
use
App\Model\LogModel
;
use
Illuminate\Http\Request
;
use
App\Http\Controllers\Controller
;
use
Illuminate\Support\Facades\DB
;
...
...
@@ -28,6 +29,8 @@ class UsersController extends Controller
$response
=
handler_drive
(
function
()
use
(
$request
)
{
LogModel
::
addlog
([
"用户登录"
=>
$request
->
all
()]);
if
(
!
$request
->
password
)
{
throw
new
ControllerException
(
'口令不能为空'
,
400
);
...
...
app/Model/LogModel.php
0 → 100644
View file @
b9a6f17b
<?php
namespace
App\Model
;
use
App\Tool\Log
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
LogModel
extends
Eloquent
{
/**
* 与模型关联的数据表
* @var string
*/
protected
$table
=
'log'
;
# 是否自动维护时间戳
public
$timestamps
=
false
;
/**
* 添加一个日志
* @param $content
* @param int $type 1 一般 2 警告 3 错误
* @param string $uid 账户标示
*/
public
static
function
addlog
(
$content
,
int
$type
=
1
,
string
$uid
=
''
,
$code
=
''
)
{
$uri
=
$_SERVER
[
'REQUEST_URI'
]
??
'cli'
;
//写入数据库
$data
=
[
'msg'
=>
$content
,
'type'
=>
$type
,
'uri'
=>
$uri
];
// self::add($data);
//写入文件
$jsonData
=
json_encode
(
$data
,
JSON_UNESCAPED_UNICODE
);
//根据类型不同,生成不同日志
if
(
$type
==
1
)
{
app
()
->
make
(
'logs'
)
::
info
(
$uid
,
$code
,
$jsonData
);
}
elseif
(
$type
==
2
)
{
app
()
->
make
(
'logs'
)
::
warn
(
$uid
,
$code
,
$jsonData
);
}
elseif
(
$type
==
3
)
{
app
()
->
make
(
'logs'
)
::
fatal
(
$uid
,
$code
,
$jsonData
);
}
}
}
\ No newline at end of file
app/Providers/AppServiceProvider.php
View file @
b9a6f17b
...
...
@@ -15,6 +15,7 @@ class AppServiceProvider extends ServiceProvider
public
function
register
()
{
//
$this
->
app
->
bind
(
'logs'
,
\App\Tool\Log
::
class
);
}
/**
...
...
app/Tool/Log.php
0 → 100755
View file @
b9a6f17b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment