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
df94d6aa
Commit
df94d6aa
authored
Apr 09, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored FileTarget.
parent
1df9114b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
FileTarget.php
framework/logging/FileTarget.php
+14
-10
No files found.
framework/logging/FileTarget.php
View file @
df94d6aa
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
*/
*/
namespace
yii\logging
;
namespace
yii\logging
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
/**
/**
...
@@ -23,15 +25,14 @@ use yii\base\InvalidConfigException;
...
@@ -23,15 +25,14 @@ use yii\base\InvalidConfigException;
class
FileTarget
extends
Target
class
FileTarget
extends
Target
{
{
/**
/**
* @var string log file path or path alias. If not set, it means the 'application.log' file under
* @var string log file path or path alias. If not set, it will use the "runtime/logs/app.log" file.
* the application runtime directory. Please make sure the directory containing
* The directory containing the log files will be automatically created if not existing.
* the log file is writable by the Web server process.
*/
*/
public
$logFile
;
public
$logFile
;
/**
/**
* @var integer maximum log file size, in kilo-bytes. Defaults to 1024
, meaning 1
MB.
* @var integer maximum log file size, in kilo-bytes. Defaults to 1024
0, meaning 10
MB.
*/
*/
public
$maxFileSize
=
1024
;
// in KB
public
$maxFileSize
=
1024
0
;
// in KB
/**
/**
* @var integer number of log files used for rotation. Defaults to 5.
* @var integer number of log files used for rotation. Defaults to 5.
*/
*/
...
@@ -46,13 +47,13 @@ class FileTarget extends Target
...
@@ -46,13 +47,13 @@ class FileTarget extends Target
{
{
parent
::
init
();
parent
::
init
();
if
(
$this
->
logFile
===
null
)
{
if
(
$this
->
logFile
===
null
)
{
$this
->
logFile
=
\Yii
::
$app
->
getRuntimePath
()
.
DIRECTORY_SEPARATOR
.
'application
.log'
;
$this
->
logFile
=
Yii
::
$app
->
getRuntimePath
()
.
'/logs/app
.log'
;
}
else
{
}
else
{
$this
->
logFile
=
\
Yii
::
getAlias
(
$this
->
logFile
);
$this
->
logFile
=
Yii
::
getAlias
(
$this
->
logFile
);
}
}
$logPath
=
dirname
(
$this
->
logFile
);
$logPath
=
dirname
(
$this
->
logFile
);
if
(
!
is_dir
(
$logPath
)
||
!
is_writable
(
$logPath
)
)
{
if
(
!
is_dir
(
$logPath
))
{
throw
new
InvalidConfigException
(
"Directory '
$logPath
' does not exist or is not writable."
);
@
mkdir
(
$logPath
,
0777
,
true
);
}
}
if
(
$this
->
maxLogFiles
<
1
)
{
if
(
$this
->
maxLogFiles
<
1
)
{
$this
->
maxLogFiles
=
1
;
$this
->
maxLogFiles
=
1
;
...
@@ -66,6 +67,7 @@ class FileTarget extends Target
...
@@ -66,6 +67,7 @@ class FileTarget extends Target
* Sends log messages to specified email addresses.
* Sends log messages to specified email addresses.
* @param array $messages the messages to be exported. See [[Logger::messages]] for the structure
* @param array $messages the messages to be exported. See [[Logger::messages]] for the structure
* of each message.
* of each message.
* @throws InvalidConfigException if unable to open the log file for writing
*/
*/
public
function
export
(
$messages
)
public
function
export
(
$messages
)
{
{
...
@@ -73,7 +75,9 @@ class FileTarget extends Target
...
@@ -73,7 +75,9 @@ class FileTarget extends Target
foreach
(
$messages
as
$message
)
{
foreach
(
$messages
as
$message
)
{
$text
.=
$this
->
formatMessage
(
$message
);
$text
.=
$this
->
formatMessage
(
$message
);
}
}
$fp
=
@
fopen
(
$this
->
logFile
,
'a'
);
if
((
$fp
=
@
fopen
(
$this
->
logFile
,
'a'
))
===
false
)
{
throw
new
InvalidConfigException
(
"Unable to append to log file:
{
$this
->
logFile
}
"
);
}
@
flock
(
$fp
,
LOCK_EX
);
@
flock
(
$fp
,
LOCK_EX
);
if
(
@
filesize
(
$this
->
logFile
)
>
$this
->
maxFileSize
*
1024
)
{
if
(
@
filesize
(
$this
->
logFile
)
>
$this
->
maxFileSize
*
1024
)
{
$this
->
rotateFiles
();
$this
->
rotateFiles
();
...
...
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