Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 25, 2024
1 parent cb4f5d9 commit 0ceacfd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 101 deletions.
4 changes: 2 additions & 2 deletions htdocs/core/class/conf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,8 @@ public function setValues($db)

require_once $handler_file_found;
$loghandlerinstance = new $handler();
if (!$loghandlerinstance instanceof LogHandlerInterface) {
throw new Exception('Log handler does not extend LogHandlerInterface');
if (!$loghandlerinstance instanceof LogHandler) {
throw new Exception('Log handler does not extend LogHandler');
}

if (empty($this->loghandlers[$handler])) {
Expand Down
27 changes: 24 additions & 3 deletions htdocs/core/modules/syslog/logHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
* or see https://www.gnu.org/
*/

require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandlerInterface.php';

/**
* Parent class for log handlers
*/
abstract class LogHandler implements LogHandlerInterface
abstract class LogHandler
{
/**
* @var string Code for the handler
Expand All @@ -38,6 +36,16 @@ abstract class LogHandler implements LogHandlerInterface
public $errors = [];


/**
* Return name of logger
*
* @return string
*/
public function getName()
{
return ucfirst($this->code);
}

/**
* Content of the info tooltip.
*
Expand Down Expand Up @@ -110,4 +118,17 @@ public function setIdent($ident)
{
$this->ident += $ident;
}

/**
* Export the message
*
* @param array $content Array containing the info about the message
* @param string $suffixinfilename When output is a file, append this suffix into default log filename.
* @return void
*/
public function export($content, $suffixinfilename = '')

Check warning on line 129 in htdocs/core/modules/syslog/logHandler.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

logHandler.php: PhanPluginUnknownArrayMethodParamType: Method \LogHandler::export has a parameter type of array for $content, but does not specify any key types or value types (Types inferred after analysis: array<string,false>|array<string,int>|array<string,mixed>|array<string,non-empty-string>|array<string,string>)
{
// Code to output log
return;
}
}
90 changes: 0 additions & 90 deletions htdocs/core/modules/syslog/logHandlerInterface.php

This file was deleted.

8 changes: 6 additions & 2 deletions htdocs/core/modules/syslog/mod_syslog_syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class mod_syslog_syslog extends LogHandler
*/
public function getName()
{
return 'Syslogd';
return 'Syslog';
}

/**
Expand Down Expand Up @@ -125,7 +125,11 @@ public function export($content, $suffixinfilename = '')

// (int) is required to avoid error parameter 3 expected to be long
openlog('dolibarr', LOG_PID | LOG_PERROR, (int) $facility);
syslog($content['level'], $content['message']);

$message = sprintf("%6s", dol_trunc($content['osuser'], 6, 'right', 'UTF-8', 1));
$message .= " ".$content['message'];

syslog($content['level'], $message);
closelog();
}
}
8 changes: 4 additions & 4 deletions htdocs/install/inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ static function ($arg) {

require_once $file;
$loghandlerinstance = new $handler();
if (!$loghandlerinstance instanceof LogHandlerInterface) {
throw new Exception('Log handler does not extend LogHandlerInterface');
if (!$loghandlerinstance instanceof LogHandler) {
throw new Exception('Log handler does not extend LogHandler');
}

if (empty($conf->loghandlers[$handler])) {
Expand Down Expand Up @@ -507,8 +507,8 @@ function conf($dolibarr_main_document_root)

require_once $file;
$loghandlerinstance = new $handler();
if (!$loghandlerinstance instanceof LogHandlerInterface) {
throw new Exception('Log handler does not extend LogHandlerInterface');
if (!$loghandlerinstance instanceof LogHandler) {
throw new Exception('Log handler does not extend LogHandler');
}

if (empty($conf->loghandlers[$handler])) {
Expand Down

0 comments on commit 0ceacfd

Please sign in to comment.