[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Log\Logger; 11 12 use Joomla\CMS\Log\Log; 13 use Joomla\CMS\Log\LogEntry; 14 use Joomla\CMS\Log\Logger; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('JPATH_PLATFORM') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Joomla! Syslog Log class 22 * 23 * This class is designed to call the PHP Syslog function call which is then sent to the 24 * system wide log system. For Linux/Unix based systems this is the syslog subsystem, for 25 * the Windows based implementations this can be found in the Event Log. For Windows, 26 * permissions may prevent PHP from properly outputting messages. 27 * 28 * @since 1.7.0 29 */ 30 class SyslogLogger extends Logger 31 { 32 /** 33 * Translation array for LogEntry priorities to SysLog priority names. 34 * 35 * @var array 36 * @since 1.7.0 37 */ 38 protected $priorities = array( 39 Log::EMERGENCY => 'EMERG', 40 Log::ALERT => 'ALERT', 41 Log::CRITICAL => 'CRIT', 42 Log::ERROR => 'ERR', 43 Log::WARNING => 'WARNING', 44 Log::NOTICE => 'NOTICE', 45 Log::INFO => 'INFO', 46 Log::DEBUG => 'DEBUG', 47 ); 48 49 /** 50 * Constructor. 51 * 52 * @param array &$options Log object options. 53 * 54 * @since 1.7.0 55 */ 56 public function __construct(array &$options) 57 { 58 // Call the parent constructor. 59 parent::__construct($options); 60 61 // Ensure that we have an identity string for the Syslog entries. 62 if (empty($this->options['sys_ident'])) { 63 $this->options['sys_ident'] = 'Joomla Platform'; 64 } 65 66 // If the option to add the process id to Syslog entries is set use it, otherwise default to true. 67 if (isset($this->options['sys_add_pid'])) { 68 $this->options['sys_add_pid'] = (bool) $this->options['sys_add_pid']; 69 } else { 70 $this->options['sys_add_pid'] = true; 71 } 72 73 // If the option to also send Syslog entries to STDERR is set use it, otherwise default to false. 74 if (isset($this->options['sys_use_stderr'])) { 75 $this->options['sys_use_stderr'] = (bool) $this->options['sys_use_stderr']; 76 } else { 77 $this->options['sys_use_stderr'] = false; 78 } 79 80 // Build the Syslog options from our log object options. 81 $sysOptions = 0; 82 83 if ($this->options['sys_add_pid']) { 84 $sysOptions = $sysOptions | LOG_PID; 85 } 86 87 if ($this->options['sys_use_stderr']) { 88 $sysOptions = $sysOptions | LOG_PERROR; 89 } 90 91 // Default logging facility is LOG_USER for Windows compatibility. 92 $sysFacility = LOG_USER; 93 94 // If we have a facility passed in and we're not on Windows, reset it. 95 if (isset($this->options['sys_facility']) && !IS_WIN) { 96 $sysFacility = $this->options['sys_facility']; 97 } 98 99 // Open the Syslog connection. 100 openlog((string) $this->options['sys_ident'], $sysOptions, $sysFacility); 101 } 102 103 /** 104 * Destructor. 105 * 106 * @since 1.7.0 107 */ 108 public function __destruct() 109 { 110 closelog(); 111 } 112 113 /** 114 * Method to add an entry to the log. 115 * 116 * @param LogEntry $entry The log entry object to add to the log. 117 * 118 * @return void 119 * 120 * @since 1.7.0 121 */ 122 public function addEntry(LogEntry $entry) 123 { 124 // Generate the value for the priority based on predefined constants. 125 $priority = \constant(strtoupper('LOG_' . $this->priorities[$entry->priority])); 126 127 // Send the entry to Syslog. 128 syslog($priority, '[' . $entry->category . '] ' . $entry->message); 129 } 130 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |