<?php
/*
* OIDplus 2.0
* Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace ViaThinkSoft\OIDplus;
// phpcs:disable PSR1.Files.SideEffects
// phpcs:enable PSR1.Files.SideEffects
class OIDplusLoggerPluginLinuxSyslog extends OIDplusLoggerPlugin {
/**
* @param string $reason
* @return bool
*/
public function available(string &$reason): bool {
$reason = _L('Functionality not available on Windows');
return false;
}
$reason = _L('File %1 does not exist','/var/log/syslog');
return false;
}
$reason = _L('File %1 is not writeable','/var/log/syslog');
return false;
}
$reason = '';
return true;
}
/**
* @param OIDplusLogEvent $event
* @return bool
*/
public function log(OIDplusLogEvent
$event): bool
{
$objects_names = array();
foreach ($event->getTargets() as $target) {
if ($target instanceof OIDplusLogTargetUser) {
$users_names[] = $target->getUsername();
} else if ($target instanceof OIDplusLogTargetObject) {
$objects_names[] = $target->getObject();
} else {
}
}
$users_info = count($users_names) == 0 ?
'' : ' ('._L
('affected users: %1',implode(', ',$users_names)).')';
$objects_info = count($objects_names) == 0 ?
'' : ' ('._L
('affected objects: %1',implode(', ',$objects_names)).')';
$ts = date('Y-m-d H:i:s');
$addr = $_SERVER['REMOTE_ADDR'] ?? _L('unknown');
$line = "[$ts] [$addr] ".$event->getMessage().$users_info.$objects_info;
}
}