Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
185eeb71
Commit
185eeb71
authored
3 years ago
by
Tim van Dijen
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite FileLoggingHandler using symfony/filesystem
parent
004d7021
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Logger/FileLoggingHandler.php
+26
-11
26 additions, 11 deletions
lib/SimpleSAML/Logger/FileLoggingHandler.php
with
26 additions
and
11 deletions
lib/SimpleSAML/Logger/FileLoggingHandler.php
+
26
−
11
View file @
185eeb71
...
...
@@ -7,6 +7,9 @@ namespace SimpleSAML\Logger;
use
SimpleSAML\Configuration
;
use
SimpleSAML\Logger
;
use
SimpleSAML\Utils
;
use
Symfony\Component\Filesystem\Filesystem
;
use
Symfony\Component\HttpFoundation\File\Exception\CannotWriteFileException
;
use
Symfony\Component\HttpFoundation\File\File
;
/**
* A logging handler that dumps logs to files.
...
...
@@ -45,6 +48,11 @@ class FileLoggingHandler implements LoggingHandlerInterface
/** @var string */
protected
string
$format
=
"%b %d %H:%M:%S"
;
/**
* @var \Symfony\Component\Filesystem\Filesystem;
*/
protected
Filesystem
$fileSystem
;
/**
* Build a new logging handler based on files.
...
...
@@ -52,6 +60,8 @@ class FileLoggingHandler implements LoggingHandlerInterface
*/
public
function
__construct
(
Configuration
$config
)
{
$this
->
fileSystem
=
new
Filesystem
();
// get the metadata handler option from the configuration
$this
->
logFile
=
$config
->
getPathValue
(
'loggingdir'
,
'log/'
)
.
$config
->
getOptionalString
(
'logging.logfile'
,
'simplesamlphp.log'
);
...
...
@@ -63,17 +73,19 @@ class FileLoggingHandler implements LoggingHandlerInterface
$config
->
getOptionalString
(
'logging.processname'
,
'SimpleSAMLphp'
)
);
if
(
@
file_exists
(
$this
->
logFile
))
{
if
(
!@
is_writeable
(
$this
->
logFile
))
{
throw
new
\Exception
(
"Could not write to logfile: "
.
$this
->
logFile
);
}
}
else
{
if
(
!@
touch
(
$this
->
logFile
))
{
throw
new
\Exception
(
"Could not create logfile: "
.
$this
->
logFile
.
" The logging directory is not writable for the web server user."
$file
=
new
File
(
$this
->
logFile
);
// Suppress E_WARNING if not exists
if
(
@
$this
->
fileSystem
->
exists
(
$this
->
logFile
))
{
if
(
!
$file
->
isWritable
())
{
throw
new
CannotWriteFileException
(
sprintf
(
"Could not write to logfile: %s"
,
$this
->
logFile
),
);
}
}
elseif
(
!
$this
->
fileSystem
->
touch
(
$this
->
logFile
))
{
throw
new
CannotWriteFileException
(
sprintf
(
"The logging directory is not writable for the web server user. Could not create logfile: %s"
,
$this
->
logFile
,
));
}
$timeUtils
=
new
Utils\Time
();
...
...
@@ -121,8 +133,11 @@ class FileLoggingHandler implements LoggingHandlerInterface
array_push
(
$replacements
,
date
(
$format
));
}
$string
=
str_replace
(
$formats
,
$replacements
,
$string
);
file_put_contents
(
$this
->
logFile
,
$string
.
\PHP_EOL
,
FILE_APPEND
);
$this
->
fileSystem
->
appendToFile
(
$this
->
logFile
,
str_replace
(
$formats
,
$replacements
,
$string
)
.
\PHP_EOL
,
false
,
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment