mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	Fixes #2998: Added framework\log\SyslogTarget that is able to write log to syslog
				
					
				
			This commit is contained in:
		@ -289,6 +289,7 @@ Yii Framework 2 Change Log
 | 
			
		||||
- New #2149: Added `yii\base\DynamicModel` to support ad-hoc data validation (qiangxue)
 | 
			
		||||
- New #2360: Added `AttributeBehavior` and `BlameableBehavior`, and renamed `AutoTimestamp` to `TimestampBehavior` (lucianobaraglia, qiangxue)
 | 
			
		||||
- New #2932: Added `yii\web\ViewAction` that allow you to render views based on GET parameter (samdark)
 | 
			
		||||
- New #2998: Added `framework\log\SyslogTarget` that is able to write log to syslog (miramir, samdark)
 | 
			
		||||
- New: Yii framework now comes with core messages in multiple languages
 | 
			
		||||
- New: Added `yii\codeception\DbTestCase` (qiangxue)
 | 
			
		||||
- New: Added `yii\web\GroupUrlRule` (qiangxue)
 | 
			
		||||
 | 
			
		||||
@ -9,7 +9,7 @@ namespace yii\log;
 | 
			
		||||
use Yii;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SyslogTarget write log to syslog.
 | 
			
		||||
 * SyslogTarget writes log to syslog.
 | 
			
		||||
 *
 | 
			
		||||
 * @author miramir <gmiramir@gmail.com>
 | 
			
		||||
 * @since 2.0
 | 
			
		||||
@ -17,9 +17,10 @@ use Yii;
 | 
			
		||||
class SyslogTarget extends Target
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string Syslog identity
 | 
			
		||||
     * @var string syslog identity
 | 
			
		||||
     */
 | 
			
		||||
    public $identity;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var integer syslog facility.
 | 
			
		||||
     */
 | 
			
		||||
@ -35,15 +36,15 @@ class SyslogTarget extends Target
 | 
			
		||||
        Logger::LEVEL_INFO => LOG_INFO,
 | 
			
		||||
        Logger::LEVEL_WARNING => LOG_WARNING,
 | 
			
		||||
        Logger::LEVEL_ERROR => LOG_ERR,
 | 
			
		||||
	];
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Writes log messages to a syslog.
 | 
			
		||||
     * Writes log messages to syslog
 | 
			
		||||
     */
 | 
			
		||||
    public function export()
 | 
			
		||||
    {
 | 
			
		||||
        openlog($this->identity, LOG_ODELAY | LOG_PID, $this->facility);
 | 
			
		||||
        foreach($this->messages as $message){
 | 
			
		||||
        foreach ($this->messages as $message) {
 | 
			
		||||
            syslog($this->syslogLevels[$message[1]], $this->formatMessage($message));
 | 
			
		||||
        }
 | 
			
		||||
        closelog();
 | 
			
		||||
@ -64,5 +65,4 @@ class SyslogTarget extends Target
 | 
			
		||||
 | 
			
		||||
        return "{$prefix}[$level][$category] $text";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user