-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Fnck/fr20180213
Fr20180213
- Loading branch information
Showing
94 changed files
with
5,564 additions
and
3,307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Copyright (C) Alibaba Cloud Computing | ||
* All rights reserved | ||
*/ | ||
|
||
/** | ||
* Class Aliyun_Log_LoggerFactory | ||
* Factory for creating logger instance, with $client, $project, $logstore, $topic configurable. | ||
* Will flush current logger when the factory instance was recycled. | ||
*/ | ||
class Aliyun_Log_LoggerFactory{ | ||
|
||
private static $loggerMap = array(); | ||
|
||
/** | ||
* Get logger instance | ||
* @param $client valid log client | ||
* @param $project which could be created in AliYun Logger Server configuration page | ||
* @param $logstore which could be created in AliYun Logger Server configuration page | ||
* @param null $topic used to specified the log by TOPIC field | ||
* @return mixed return logger instance | ||
* @throws Exception if the input parameter is invalid, throw exception | ||
*/ | ||
public static function getLogger($client, $project, $logstore, $topic = null){ | ||
if($project === null || $project == ''){ | ||
throw new Exception('project name is blank!'); | ||
} | ||
if($logstore === null || $logstore == ''){ | ||
throw new Exception('logstore name is blank!'); | ||
} | ||
if($topic === null){ | ||
$topic = ''; | ||
} | ||
$loggerKey = $project.'#'.$logstore.'#'.$topic; | ||
if (!array_key_exists($loggerKey, static::$loggerMap)) | ||
{ | ||
$instanceSimpleLogger = new Aliyun_Log_SimpleLogger($client,$project,$logstore,$topic); | ||
static::$loggerMap[$loggerKey] = $instanceSimpleLogger; | ||
} | ||
return static::$loggerMap[$loggerKey]; | ||
} | ||
|
||
/** | ||
* set modifier to protected for singleton pattern | ||
* Aliyun_Log_LoggerFactory constructor. | ||
*/ | ||
protected function __construct() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* set clone function to private for singleton pattern | ||
*/ | ||
private function __clone() | ||
{} | ||
|
||
/** | ||
* flush current logger in destruct function | ||
*/ | ||
function __destruct() { | ||
if(static::$loggerMap != null){ | ||
foreach (static::$loggerMap as $innerLogger){ | ||
$innerLogger->logFlush(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* Copyright (C) Alibaba Cloud Computing | ||
* All rights reserved | ||
*/ | ||
|
||
class Aliyun_Log_Models_LogLevel_LogLevel{ | ||
const debug = 'debug'; | ||
const info = 'info'; | ||
const warn = 'warn'; | ||
const error = 'error'; | ||
|
||
private static $constCacheArray = NULL; | ||
|
||
private $level; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $level | ||
*/ | ||
private function __construct($level) { | ||
$this->level = $level; | ||
} | ||
|
||
/** | ||
* Compares two logger levels. | ||
* | ||
* @param LoggerLevels $other | ||
* @return boolean | ||
*/ | ||
public function equals($other) { | ||
if($other instanceof Aliyun_Log_Models_LogLevel_LogLevel) { | ||
if($this->level == $other->level) { | ||
return true; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public static function getLevelDebug(){ | ||
if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::debug])){ | ||
self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::debug] = new Aliyun_Log_Models_LogLevel_LogLevel('debug'); | ||
} | ||
return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::debug]; | ||
} | ||
|
||
public static function getLevelInfo(){ | ||
if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::info])){ | ||
self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::info] = new Aliyun_Log_Models_LogLevel_LogLevel('info'); | ||
} | ||
return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::info]; | ||
} | ||
|
||
public static function getLevelWarn(){ | ||
if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::warn])){ | ||
self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::warn] = new Aliyun_Log_Models_LogLevel_LogLevel('warn'); | ||
} | ||
return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::warn]; | ||
} | ||
|
||
public static function getLevelError(){ | ||
if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::error])){ | ||
self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::error] = new Aliyun_Log_Models_LogLevel_LogLevel('error'); | ||
} | ||
return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::error]; | ||
} | ||
|
||
public static function getLevelStr(Aliyun_Log_Models_LogLevel_LogLevel $logLevel){ | ||
|
||
$logLevelStr = ''; | ||
if(null === $logLevel){ | ||
$logLevelStr = 'info'; | ||
} | ||
switch ($logLevel->level){ | ||
case "error": | ||
$logLevelStr= 'error'; | ||
break; | ||
case "warn": | ||
$logLevelStr= 'warn'; | ||
break; | ||
case "info": | ||
$logLevelStr= 'info'; | ||
break; | ||
case "debug": | ||
$logLevelStr= 'debug'; | ||
break; | ||
} | ||
return $logLevelStr; | ||
} | ||
} |
Oops, something went wrong.