Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
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
PSDI Army
yii2
Commits
171cab2d
Commit
171cab2d
authored
Apr 09, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'SyslogTarget' of github.com:miramir/yii2 into miramir-SyslogTarget
parents
e59b2d89
bdbcadbe
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
SyslogTarget.php
framework/log/SyslogTarget.php
+68
-0
No files found.
framework/log/SyslogTarget.php
0 → 100644
View file @
171cab2d
<?php
/**
* @link http://www.yiiframework.com/
* @license http://www.yiiframework.com/license/
*/
namespace
yii\log
;
use
Yii
;
/**
* SyslogTarget write log to syslog.
*
* @author miramir <gmiramir@gmail.com>
* @since 2.0
*/
class
SyslogTarget
extends
Target
{
/**
* @var string Syslog identity
*/
public
$identity
;
/**
* @var integer syslog facility.
*/
public
$facility
=
LOG_SYSLOG
;
/**
* @var array syslog levels
*/
private
$syslogLevels
=
[
Logger
::
LEVEL_TRACE
=>
LOG_DEBUG
,
Logger
::
LEVEL_PROFILE_BEGIN
=>
LOG_DEBUG
,
Logger
::
LEVEL_PROFILE_END
=>
LOG_DEBUG
,
Logger
::
LEVEL_INFO
=>
LOG_INFO
,
Logger
::
LEVEL_WARNING
=>
LOG_WARNING
,
Logger
::
LEVEL_ERROR
=>
LOG_ERR
,
];
/**
* Writes log messages to a syslog.
*/
public
function
export
()
{
openlog
(
$this
->
identity
,
LOG_ODELAY
|
LOG_PID
,
$this
->
facility
);
foreach
(
$this
->
messages
as
$message
){
syslog
(
$this
->
syslogLevels
[
$message
[
1
]],
$this
->
formatMessage
(
$message
));
}
closelog
();
}
/**
* @inheritdoc
*/
public
function
formatMessage
(
$message
)
{
list
(
$text
,
$level
,
$category
,
$timestamp
)
=
$message
;
$level
=
Logger
::
getLevelName
(
$level
);
if
(
!
is_string
(
$text
))
{
$text
=
var_export
(
$text
,
true
);
}
$prefix
=
$this
->
prefix
?
call_user_func
(
$this
->
prefix
,
$message
)
:
$this
->
getMessagePrefix
(
$message
);
return
"
{
$prefix
}
[
$level
][
$category
]
$text
"
;
}
}
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