Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-rpc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
without authentication
meibuyu-rpc
Commits
e0ce58c9
Commit
e0ce58c9
authored
Jun 02, 2020
by
fuyunnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加记录日志方法
parent
f8374663
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
functions.php
src/functions.php
+39
-0
No files found.
src/functions.php
View file @
e0ce58c9
...
...
@@ -3,8 +3,12 @@
use
Hyperf\Cache\Listener\DeleteListenerEvent
;
use
Hyperf\HttpServer\Contract\RequestInterface
;
use
Hyperf\HttpServer\Contract\ResponseInterface
;
use
Hyperf\Logger\Logger
;
use
Hyperf\Redis\Redis
;
use
Hyperf\Utils\ApplicationContext
;
use
Monolog\Formatter\LineFormatter
;
use
Monolog\Handler\FirePHPHandler
;
use
Monolog\Handler\StreamHandler
;
use
Psr\EventDispatcher\EventDispatcherInterface
;
/**
...
...
@@ -414,6 +418,38 @@ if (!function_exists('get_week_start_and_end')) {
}
}
if
(
!
function_exists
(
'putLog'
))
{
/**
* description:记录日志 文件会生成在当前项目 /runtime/dev/当前日期名称
* author: fuyunnan
* @param string|array $output 日志内容
* @param string $dir 目录
* date: 2020/3/18
* @throws
* @return void
*/
function
putLog
(
$output
=
'out-mes'
,
$dir
=
BASE_PATH
.
'/runtime/dev/'
)
{
!
is_dir
(
$dir
)
&&
!
mkdir
(
$dir
,
0777
,
true
);
// 创建一个 Channel,参数 log 即为 Channel 的名字
$log
=
new
Logger
(
''
);
// 创建两个 Handler,对应变量 $stream 和 $fire
$filename
=
$dir
.
date
(
'Y-m-d'
,
time
())
.
'.log'
;
$stream
=
new
StreamHandler
(
$filename
,
Logger
::
WARNING
);
$fire
=
new
FirePHPHandler
();
if
(
is_array
(
$output
))
{
$output
=
var_export
(
$output
,
true
);
}
$output
=
'[ '
.
date
(
'H:i:s'
,
time
())
.
' ] --- '
.
$output
;
$formatter
=
new
LineFormatter
(
$output
.
"
\r\n
"
);
$stream
->
setFormatter
(
$formatter
);
$log
->
pushHandler
(
$stream
);
$log
->
pushHandler
(
$fire
);
$log
->
alert
(
''
);
}
}
if
(
!
function_exists
(
'empty_string_2_null'
))
{
/**
* 空字符串转NULL
...
...
@@ -437,3 +473,6 @@ if (!function_exists('empty_string_2_null')) {
}
}
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