Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webbasics
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webbasics
Commits
b506859d
Commit
b506859d
authored
Jul 22, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapted logger + unit tests to work on Linux.
parent
20bfea03
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
83 deletions
+71
-83
logger.php
logger.php
+46
-44
tests/test_logger.php
tests/test_logger.php
+25
-39
No files found.
logger.php
View file @
b506859d
...
...
@@ -24,7 +24,7 @@ class Logger extends Base {
const
INFO
=
3
;
const
DEBUG
=
4
;
static
$level_names
=
array
(
'CRITICAL'
,
'ERROR'
,
'WARNING'
,
'INFO'
,
'DEBUG'
);
private
static
$allowed_dump_formats
=
array
(
'plain'
,
'html'
,
'file'
);
private
static
$allowed_dump_formats
=
array
(
'plain'
,
'html'
,
'file'
,
'none'
);
const
DEFAULT_FORMAT
=
'%(datetime): %(level): %(message)'
;
...
...
@@ -136,6 +136,8 @@ class Logger extends Base {
function
dump
(
$file_prefix
=
'log'
)
{
switch
(
$this
->
dump_format
)
{
case
'none'
:
return
;
case
'plain'
:
echo
$this
->
dumps
();
break
;
...
...
@@ -154,7 +156,7 @@ class Logger extends Base {
function
save
(
$path
)
{
if
(
$this
->
log_directory
&&
!
is_dir
(
$this
->
log_directory
)
)
mkdir
(
$this
->
log_directory
,
0
644
,
true
);
mkdir
(
$this
->
log_directory
,
0
777
,
true
);
file_put_contents
(
$this
->
log_directory
.
$path
,
$this
->
dumps
());
}
...
...
tests/test_logger.php
View file @
b506859d
...
...
@@ -173,23 +173,9 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
$this
->
assertRegExp
(
'/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/'
,
$filename
);
}
/**
* @depends test_dump_file_regular
*/
function
test_dump_file_prefix
()
{
$this
->
logger
->
set_directory
(
LOGDIR
);
$this
->
logger
->
set_dump_format
(
'file'
);
$this
->
logger
->
warning
(
'test message'
);
$this
->
logger
->
dump
(
'error'
);
$filename
=
$this
->
find_logfile
();
$this
->
assertStringEqualsFile
(
LOGDIR
.
$filename
,
'WARNING: test message'
);
unlink
(
LOGDIR
.
$filename
);
$this
->
assertRegExp
(
'/^error_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/'
,
$filename
);
}
function
test_handle_exception
()
{
$this
->
logger
->
handle_exception
(
new
Exception
(
'test message'
));
$this
->
logger
->
set_dump_format
(
'none'
);
$this
->
logger
->
handle_exception
(
new
RuntimeException
(
'test message'
));
$this
->
assertNotEquals
(
$this
->
logger
->
dumps
(),
''
);
}
}
...
...
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