Skip to content
Snippets Groups Projects
Commit 5832b4de authored by Lasse Birnbaum Jensen's avatar Lasse Birnbaum Jensen
Browse files

Added options to configure processname for logging. Usefull when having...

Added options to configure processname for logging. Usefull when having multiple installations on the same machine.

Processname in the log is determined by the 'logging.processname' configuration key. It defaults to "simpleSAMLphp" if not set.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@667 44740490-163a-0410-bde0-09ae8108e29a
parent 238ec6ed
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,7 @@ $config = array ( ...@@ -89,7 +89,7 @@ $config = array (
*/ */
'logging.level' => LOG_NOTICE, 'logging.level' => LOG_NOTICE,
'logging.handler' => 'syslog', 'logging.handler' => 'syslog',
'logging.processname' => 'simpleSAMLphp',
/* Logging: syslog - Choose a syslog facility to use for logging. /* Logging: syslog - Choose a syslog facility to use for logging.
*/ */
'logging.facility' => LOG_LOCAL5, 'logging.facility' => LOG_LOCAL5,
......
...@@ -23,17 +23,21 @@ class SimpleSAML_Logger_LoggingHandlerErrorLog implements SimpleSAML_Logger_Logg ...@@ -23,17 +23,21 @@ class SimpleSAML_Logger_LoggingHandlerErrorLog implements SimpleSAML_Logger_Logg
LOG_NOTICE => 'NOTICE', LOG_NOTICE => 'NOTICE',
LOG_INFO => 'INFO', LOG_INFO => 'INFO',
LOG_DEBUG => 'DEBUG', LOG_DEBUG => 'DEBUG',
); );
function log_internal($level, $string) { function log_internal($level, $string) {
$config = SimpleSAML_Configuration::getInstance();
assert($config instanceof SimpleSAML_Configuration);
$processname = $config->getValue('logging.processname','simpleSAMLphp');
if(array_key_exists($level, self::$levelNames)) { if(array_key_exists($level, self::$levelNames)) {
$levelName = self::$levelNames[$level]; $levelName = self::$levelNames[$level];
} else { } else {
$levelName = sprintf('UNKNOWN%d', $level); $levelName = sprintf('UNKNOWN%d', $level);
} }
error_log($levelName . ': ' . $string); error_log($processname.' - '.$levelName . ': ' . $string);
} }
} }
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingHandler { class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingHandler {
private $logFile = null; private $logFile = null;
private $processname = null;
function __construct() { function __construct() {
$config = SimpleSAML_Configuration::getInstance(); $config = SimpleSAML_Configuration::getInstance();
...@@ -19,7 +20,8 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH ...@@ -19,7 +20,8 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH
/* Get the metadata handler option from the configuration. */ /* Get the metadata handler option from the configuration. */
$this->logFile = $config->getPathValue('loggingdir').$config->getValue('logging.logfile'); $this->logFile = $config->getPathValue('loggingdir').$config->getValue('logging.logfile');
$this->processname = $config->getValue('logging.processname','simpleSAMLphp');
if (@file_exists($this->logFile)) { if (@file_exists($this->logFile)) {
if (!@is_writeable($this->logFile)) throw new Exception("Could not write to logfile: ".$this->logFile); if (!@is_writeable($this->logFile)) throw new Exception("Could not write to logfile: ".$this->logFile);
} }
...@@ -31,7 +33,7 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH ...@@ -31,7 +33,7 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH
function log_internal($level,$string) { function log_internal($level,$string) {
if ($this->logFile != null) { if ($this->logFile != null) {
$line = sprintf("%s ssp %d %s\n",strftime("%b %d %H:%M:%S"),$level,$string); $line = sprintf("%s %s %d %s\n",strftime("%b %d %H:%M:%S"),$this->processname,$level,$string);
file_put_contents($this->logFile,$line,FILE_APPEND); file_put_contents($this->logFile,$line,FILE_APPEND);
} }
} }
......
...@@ -16,7 +16,8 @@ class SimpleSAML_Logger_LoggingHandlerSyslog implements SimpleSAML_Logger_Loggin ...@@ -16,7 +16,8 @@ class SimpleSAML_Logger_LoggingHandlerSyslog implements SimpleSAML_Logger_Loggin
function __construct() { function __construct() {
$config = SimpleSAML_Configuration::getInstance(); $config = SimpleSAML_Configuration::getInstance();
assert($config instanceof SimpleSAML_Configuration); assert($config instanceof SimpleSAML_Configuration);
$facility = $config->getValue('logging.facility'); $facility = $config->getValue('logging.facility');
$processname = $config->getValue('logging.processname','simpleSAMLphp');
/* /*
* OS Check * OS Check
* Setting facility to LOG_USER (only valid in Windows), enable log level rewrite on windows systems. * Setting facility to LOG_USER (only valid in Windows), enable log level rewrite on windows systems.
...@@ -26,7 +27,7 @@ class SimpleSAML_Logger_LoggingHandlerSyslog implements SimpleSAML_Logger_Loggin ...@@ -26,7 +27,7 @@ class SimpleSAML_Logger_LoggingHandlerSyslog implements SimpleSAML_Logger_Loggin
$facility = LOG_USER; $facility = LOG_USER;
} }
openlog("simpleSAMLphp", LOG_PID, $facility); openlog($processname, LOG_PID, $facility);
} }
function log_internal($level,$string) { function log_internal($level,$string) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment