MainLogger can now have debug level disabled

This commit is contained in:
Shoghi Cervantes 2014-05-29 00:08:02 +02:00
parent 7bd6f2ed91
commit 8d40f843cf
38 changed files with 132 additions and 104 deletions

View File

@ -82,7 +82,6 @@ use pocketmine\tile\Sign;
use pocketmine\tile\Spawnable;
use pocketmine\tile\Tile;
use pocketmine\utils\Binary;
use pocketmine\utils\MainLogger;
use pocketmine\utils\TextFormat;
/**
@ -2128,7 +2127,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
}
$this->currentTransaction = null;
}
@ -2136,7 +2134,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
}
break;
case ProtocolInfo::SEND_INVENTORY_PACKET: //TODO, Mojang, enable this ´^_^`
if($this->spawned === false){
@ -2374,6 +2371,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return $cnt;
}else{
$this->removeWindow($inventory);
return -1;
}
}

View File

@ -68,7 +68,6 @@ namespace pocketmine {
use pocketmine\utils\Binary;
use pocketmine\utils\LogLevel;
use pocketmine\utils\MainLogger;
use pocketmine\utils\TextFormat;
use pocketmine\utils\Utils;
use pocketmine\wizard\Installer;
@ -210,25 +209,6 @@ namespace pocketmine {
return true;
}
function log($message, $name, $EOL = true, $level = 2, $close = false){
global $fpointers;
if((!defined("pocketmine\\DEBUG") or \pocketmine\DEBUG >= $level) and (!defined("pocketmine\\LOG") or \pocketmine\LOG === true)){
$message .= $EOL === true ? PHP_EOL : "";
if(!isset($fpointers)){
$fpointers = [];
}
if(!isset($fpointers[$name]) or $fpointers[$name] === false){
$fpointers[$name] = @fopen(\pocketmine\DATA . "/" . $name . ".log", "ab");
}
@fwrite($fpointers[$name], $message);
if($close === true){
fclose($fpointers[$name]);
unset($fpointers[$name]);
}
}
}
set_error_handler("\\pocketmine\\error_handler", E_ALL);
$errors = 0;

View File

@ -85,6 +85,7 @@ use pocketmine\tile\Tile;
use pocketmine\utils\Binary;
use pocketmine\utils\Config;
use pocketmine\utils\Logger;
use pocketmine\utils\MainLogger;
use pocketmine\utils\TextFormat;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
@ -1275,6 +1276,9 @@ class Server{
}
define("pocketmine\\DEBUG", $this->getConfigInt("debug.level", 1));
if($this->logger instanceof MainLogger){
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
}
define("ADVANCED_CACHE", $this->getConfigBoolean("enable-advanced-cache", false));
define("MAX_CHUNK_RATE", 20 / $this->getConfigInt("max-chunks-per-second", 7)); //Default rate ~448 kB/s
if(ADVANCED_CACHE == true){
@ -1311,7 +1315,6 @@ class Server{
$this->enablePlugins(PluginLoadOrder::STARTUP);
Generator::addGenerator("pocketmine\\level\\generator\\Flat", "flat");
Generator::addGenerator("pocketmine\\level\\generator\\Normal", "normal");
Generator::addGenerator("pocketmine\\level\\generator\\Normal", "default");

View File

@ -20,6 +20,7 @@
*/
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;

View File

@ -24,11 +24,9 @@
*/
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\Player;
@ -718,7 +716,7 @@ abstract class Block extends Position implements Metadatable{
* Checks for collision against an AxisAlignedBB
*
* @param AxisAlignedBB $bb
* @param Block[] $list
* @param Block[] $list
*/
public function collidesWithBB(AxisAlignedBB $bb, &$list = array()){
$bb2 = $this->getBoundingBox();

View File

@ -21,11 +21,8 @@
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\Server;

View File

@ -134,6 +134,7 @@ class DroppedItem extends Entity{
public function getData(){
$flags = 0;
$flags |= $this->fireTicks > 0 ? 1 : 0;
return [
0 => array("type" => 0, "value" => $flags),
1 => array("type" => 1, "value" => 0),

View File

@ -24,6 +24,7 @@
*/
namespace pocketmine\entity;
use pocketmine\block\Block;
use pocketmine\event\entity\EntityDespawnEvent;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\entity\EntityMotionEvent;
@ -40,16 +41,15 @@ use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Short;
use pocketmine\Network;
use pocketmine\network\protocol\MoveEntityPacket_PosRot;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetTimePacket;
use pocketmine\Network;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
use pocketmine\block\Block;
abstract class Entity extends Position implements Metadatable{
public static $entityCount = 1;
@ -140,16 +140,16 @@ abstract class Entity extends Position implements Metadatable{
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->setPositionAndRotation(new Vector3(
$this->namedtag["Pos"][0],
$this->namedtag["Pos"][1],
$this->namedtag["Pos"][2]),
$this->namedtag["Pos"][0],
$this->namedtag["Pos"][1],
$this->namedtag["Pos"][2]),
$this->namedtag->Rotation[0],
$this->namedtag->Rotation[1]
);
$this->setMotion(new Vector3(
$this->namedtag["Motion"][0],
$this->namedtag["Motion"][1],
$this->namedtag["Motion"][2])
$this->namedtag["Motion"][0],
$this->namedtag["Motion"][1],
$this->namedtag["Motion"][2])
);
if(!isset($this->namedtag->FallDistance)){
@ -330,11 +330,13 @@ abstract class Entity extends Position implements Metadatable{
if($direction === 0){
$this->motionX = -$force;
return true;
}
if($direction === 1){
$this->motionX = $force;
return true;
}
@ -342,11 +344,13 @@ abstract class Entity extends Position implements Metadatable{
if($direction === 3){
$this->motionY = $force;
return true;
}
if($direction === 4){
$this->motionZ = -$force;
return true;
}
@ -363,6 +367,7 @@ abstract class Entity extends Position implements Metadatable{
//TODO: check vehicles
if($this->dead === true){
$this->close();
return false;
}
@ -461,6 +466,7 @@ abstract class Entity extends Position implements Metadatable{
$hasUpdate = $this->entityBaseTick();
$this->updateMovement();
//if($this->isStatic())
return true;
//return !($this instanceof Player);

View File

@ -24,16 +24,15 @@ namespace pocketmine\entity;
use pocketmine\inventory\InventoryHolder;
use pocketmine\inventory\PlayerInventory;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Short;
use pocketmine\Network;
use pocketmine\network\protocol\AddPlayerPacket;
use pocketmine\network\protocol\RemovePlayerPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Network;
use pocketmine\Player;
class Human extends Creature implements ProjectileSource, InventoryHolder{

View File

@ -20,12 +20,11 @@
*/
namespace pocketmine\event\inventory;
use pocketmine\event\Cancellable;
use pocketmine\event\Event;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\CraftingTransactionGroup;
use pocketmine\inventory\Recipe;
use pocketmine\Player;
class CraftItemEvent extends Event implements Cancellable{
public static $handlerList = null;

View File

@ -20,6 +20,7 @@
*/
namespace pocketmine\event\inventory;
use pocketmine\inventory\Inventory;
use pocketmine\Player;

View File

@ -20,6 +20,7 @@
*/
namespace pocketmine\event\inventory;
use pocketmine\event\Cancellable;
use pocketmine\inventory\Inventory;
use pocketmine\Player;

View File

@ -20,6 +20,7 @@
*/
namespace pocketmine\event\inventory;
use pocketmine\event\Cancellable;
use pocketmine\inventory\Inventory;
use pocketmine\item\Item;

View File

@ -20,11 +20,10 @@
*/
namespace pocketmine\event\inventory;
use pocketmine\event\Cancellable;
use pocketmine\event\Event;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\TransactionGroup;
use pocketmine\Player;
/**
* Called when there is a transaction between two Inventory objects.

View File

@ -21,8 +21,8 @@
namespace pocketmine\event\player;
use pocketmine\Event;
use pocketmine\event\Cancellable;
use pocketmine\Event;
use pocketmine\item\Item;
use pocketmine\Player;

View File

@ -21,8 +21,8 @@
namespace pocketmine\event\server;
use pocketmine\event\Cancellable;
use pocketmine\event;
use pocketmine\event\Cancellable;
use pocketmine\network\protocol\DataPacket;
use pocketmine\Player;

View File

@ -21,8 +21,8 @@
namespace pocketmine\event\server;
use pocketmine\event\Cancellable;
use pocketmine\event;
use pocketmine\event\Cancellable;
use pocketmine\network\protocol\DataPacket;
use pocketmine\Player;

View File

@ -133,6 +133,7 @@ abstract class BaseInventory implements Inventory{
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $this->getItem($index), $item, $index));
if($ev->isCancelled()){
$this->sendContents($this->getViewers());
return false;
}
$item = $ev->getNewItem();
@ -220,6 +221,7 @@ abstract class BaseInventory implements Inventory{
return true;
}
}
return false;
}
@ -258,6 +260,7 @@ abstract class BaseInventory implements Inventory{
break;
}
}
return $slots;
}
@ -353,6 +356,7 @@ abstract class BaseInventory implements Inventory{
return false;
}
$this->onOpen($who);
return true;
}

View File

@ -21,10 +21,10 @@
namespace pocketmine\inventory;
use pocketmine\math\Vector3;
use pocketmine\network\protocol\ContainerClosePacket;
use pocketmine\network\protocol\ContainerOpenPacket;
use pocketmine\Player;
use pocketmine\math\Vector3;
abstract class ContainerInventory extends BaseInventory{
public function onOpen(Player $who){

View File

@ -22,7 +22,6 @@
namespace pocketmine\inventory;
use pocketmine\block\Planks;
use pocketmine\block\Slab;
use pocketmine\block\Wood;
use pocketmine\item\Item;
@ -303,10 +302,10 @@ class CraftingManager{
* @return FurnaceRecipe
*/
public function matchFurnaceRecipe(Item $input){
if(isset($this->furnaceRecipes[$input->getID().":".$input->getDamage()])){
return $this->furnaceRecipes[$input->getID().":".$input->getDamage()];
}elseif($this->furnaceRecipes[$input->getID().":?"]){
return $this->furnaceRecipes[$input->getID().":?"];
if(isset($this->furnaceRecipes[$input->getID() . ":" . $input->getDamage()])){
return $this->furnaceRecipes[$input->getID() . ":" . $input->getDamage()];
}elseif($this->furnaceRecipes[$input->getID() . ":?"]){
return $this->furnaceRecipes[$input->getID() . ":?"];
}
return null;
@ -329,9 +328,9 @@ class CraftingManager{
$ingredients = $recipe->getIngredientList();
usort($ingredients, array($this, "sort"));
foreach($ingredients as $item){
$hash .= $item->getID().":".($item->getDamage() === null ? "?":$item->getDamage())."x".$item->getCount().",";
$hash .= $item->getID() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
}
$this->recipeLookup[$result->getID().":".$result->getDamage()][$hash] = $recipe;
$this->recipeLookup[$result->getID() . ":" . $result->getDamage()][$hash] = $recipe;
}
/**
@ -339,7 +338,7 @@ class CraftingManager{
*/
public function registerFurnaceRecipe(FurnaceRecipe $recipe){
$input = $recipe->getInput();
$this->furnaceRecipes[$input->getID().":".($input->getDamage() === null ? "?":$input->getDamage())] = $recipe;
$this->furnaceRecipes[$input->getID() . ":" . ($input->getDamage() === null ? "?" : $input->getDamage())] = $recipe;
}
/**
@ -353,7 +352,7 @@ class CraftingManager{
if(!($result instanceof Item)){
return false;
}
$k = $result->getID().":".$result->getDamage();
$k = $result->getID() . ":" . $result->getDamage();
if(!isset($this->recipeLookup[$k])){
return false;
@ -364,7 +363,7 @@ class CraftingManager{
$inputCount = 0;
foreach($input as $item){
$inputCount += $item->getCount();
$hash .= $item->getID().":".($item->getDamage() === null ? "?":$item->getDamage())."x".$item->getCount().",";
$hash .= $item->getID() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
}
if(!isset($this->recipeLookup[$k][$hash])){
$hasRecipe = null;
@ -414,6 +413,7 @@ class CraftingManager{
if($checkResult->equals($result, true) and $checkResult->getCount() === $result->getCount()){
return $recipe;
}
return null;
}

View File

@ -64,6 +64,7 @@ class CraftingTransactionGroup extends SimpleTransactionGroup{
*/
public function getResult(){
reset($this->output);
return current($this->output);
}
@ -71,6 +72,7 @@ class CraftingTransactionGroup extends SimpleTransactionGroup{
if(count($this->output) !== 1 or count($this->input) === 0){
return false;
}
return $this->getMatchingRecipe() instanceof Recipe;
}
@ -81,6 +83,7 @@ class CraftingTransactionGroup extends SimpleTransactionGroup{
if($this->recipe === null){
$this->recipe = Server::getInstance()->getCraftingManager()->matchTransaction($this);
}
return $this->recipe;
}
@ -94,6 +97,7 @@ class CraftingTransactionGroup extends SimpleTransactionGroup{
foreach($this->inventories as $inventory){
$inventory->sendContents($inventory->getViewers());
}
return false;
}

View File

@ -45,11 +45,11 @@ class ShapedRecipe implements Recipe{
throw new \Exception("Must provide a shape");
}
if(count($shape) > 3){
throw new \Exception("Crafting recipes should be 1, 2, 3 rows, not ".count($shape));
throw new \Exception("Crafting recipes should be 1, 2, 3 rows, not " . count($shape));
}
foreach($shape as $row){
if(strlen($row) === 0 or strlen($row) > 3){
throw new \Exception("Crafting rows should be 1, 2, 3 characters, not ".count($row));
throw new \Exception("Crafting rows should be 1, 2, 3 characters, not " . count($row));
}
$this->rows[] = $row;
$len = strlen($row);
@ -70,7 +70,7 @@ class ShapedRecipe implements Recipe{
*/
public function setIngredient($key, Item $item){
if(!isset($this->ingredients[$key])){
throw new \Exception("Symbol does not appear in the shape: ". $key);
throw new \Exception("Symbol does not appear in the shape: " . $key);
}
$this->ingredients[$key] = $item;
@ -90,6 +90,7 @@ class ShapedRecipe implements Recipe{
$ingredients[$key] = $ingredient;
}
}
return $ingredients;
}

View File

@ -77,6 +77,7 @@ class ShapelessRecipe implements Recipe{
$item->setCount($item->getCount() - 1);
}
}
return $this;
}
@ -88,6 +89,7 @@ class ShapelessRecipe implements Recipe{
foreach($this->ingredients as $ingredient){
$ingredients[] = clone $ingredient;
}
return $ingredients;
}
@ -99,6 +101,7 @@ class ShapelessRecipe implements Recipe{
foreach($this->ingredients as $ingredient){
$count += $ingredient->getCount();
}
return $count;
}

View File

@ -126,6 +126,7 @@ class SimpleTransactionGroup implements TransactionGroup{
$haveItems = [];
$needItems = [];
$this->matchItems($haveItems, $needItems);
return count($haveItems) === 0 and count($needItems) === 0 and count($this->transactions) > 0;
}
@ -139,6 +140,7 @@ class SimpleTransactionGroup implements TransactionGroup{
foreach($this->inventories as $inventory){
$inventory->sendContents($inventory->getViewers());
}
return false;
}

View File

@ -21,8 +21,6 @@
namespace pocketmine\inventory;
use pocketmine\item\Item;
interface TransactionGroup{
/**

View File

@ -440,6 +440,7 @@ class Item{
}else{
$item = new Item($id, $meta, $count);
}
return $item;
}

View File

@ -28,7 +28,6 @@ use pocketmine\event\entity\EntityExplodeEvent;
use pocketmine\item\Item;
use pocketmine\math\Vector3 as Vector3;
use pocketmine\network\protocol\ExplodePacket;
use pocketmine\Player;
use pocketmine\Server;
class Explosion{

View File

@ -33,7 +33,6 @@ use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\item\Item;
use pocketmine\level\format\pmf\LevelFormat;
use pocketmine\level\generator\Flat;
use pocketmine\level\generator\Generator;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector2;
@ -536,6 +535,7 @@ class Level{
public function isFullBlock(Vector3 $pos){
$bb = $this->getBlock($pos)->getBoundingBox();
return $bb instanceof AxisAlignedBB and $bb->getAverageEdgeLength() >= 1;
}
@ -685,26 +685,26 @@ class Level{
if($item->getID() !== Item::AIR and $item->getCount() > 0){
$itemEntity = new DroppedItem($this, new Compound("", [
"Pos" => new Enum("Pos", [
new Double("", $source->getX()),
new Double("", $source->getY()),
new Double("", $source->getZ())
]),
new Double("", $source->getX()),
new Double("", $source->getY()),
new Double("", $source->getZ())
]),
//TODO: add random motion with physics
"Motion" => new Enum("Motion", [
new Double("", (lcg_value() * 0.2 - 0.1) * $force),
new Double("", 0.2 * $force),
new Double("", (lcg_value() * 0.2 - 0.1) * $force)
]),
new Double("", (lcg_value() * 0.2 - 0.1) * $force),
new Double("", 0.2 * $force),
new Double("", (lcg_value() * 0.2 - 0.1) * $force)
]),
"Rotation" => new Enum("Rotation", [
new Float("", lcg_value() * 360),
new Float("", 0)
]),
new Float("", lcg_value() * 360),
new Float("", 0)
]),
"Health" => new Short("Health", 5),
"Item" => new Compound("Item", [
"id" => new Short("id", $item->getID()),
"Damage" => new Short("Damage", $item->getDamage()),
"Count" => new Byte("Count", $item->getCount())
]),
"id" => new Short("id", $item->getID()),
"Damage" => new Short("Damage", $item->getDamage()),
"Count" => new Byte("Count", $item->getCount())
]),
"PickupDelay" => new Short("PickupDelay", 10)
]));
@ -772,6 +772,7 @@ class Level{
}
}
}
return true;
}
@ -825,6 +826,7 @@ class Level{
$hand->position($block);
}elseif($block->getID() === Item::FIRE){
$this->setBlock($block, new Air(), true, false, true);
return false;
}else{
return false;
@ -884,6 +886,7 @@ class Level{
if($item->getCount() <= 0){
$item = Item::get(Item::AIR, 0, 0);
}
return true;
}

View File

@ -37,6 +37,7 @@ class BlockMetadataStore extends MetadataStore{
if(!($block instanceof Block)){
throw new \InvalidArgumentException("Argument must be a Block instance");
}
return $block->x . ":" . $block->y . ":" . $block->z . ":" . $metadataKey;
}

View File

@ -29,6 +29,7 @@ class EntityMetadataStore extends MetadataStore{
if(!($entity instanceof Entity)){
throw new \InvalidArgumentException("Argument must be an Entity instance");
}
return $entity->getID() . ":" . $metadataKey;
}
}

View File

@ -29,6 +29,7 @@ class LevelMetadataStore extends MetadataStore{
if(!($level instanceof Level)){
throw new \InvalidArgumentException("Argument must be a Level instance");
}
return strtolower($level->getName()) . ":" . $metadataKey;
}
}

View File

@ -29,6 +29,7 @@ class PlayerMetadataStore extends MetadataStore{
if(!($player instanceof OfflinePlayer)){
throw new \InvalidArgumentException("Argument must be an OfflinePlayer instance");
}
return strtolower($player->getName()) . ":" . $metadataKey;
}
}

View File

@ -52,6 +52,7 @@ class PluginDescription{
/**
* @param array $plugin
*
* @throws \Exception
*/
private function loadMap(array $plugin){

View File

@ -21,12 +21,9 @@
namespace pocketmine\plugin;
use pocketmine\level\Level;
use pocketmine\Server;
use pocketmine\utils\Logger;
use pocketmine\utils\LogLevel;
use pocketmine\utils\MainLogger;
use pocketmine\utils\TextFormat;
class PluginLogger implements Logger{

View File

@ -437,6 +437,7 @@ class PluginManager{
unset($this->permSubs[$permission][$k]);
}
}
return $subs;
}

View File

@ -86,7 +86,7 @@ interface Logger{
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param mixed $level
* @param string $message
*/
public function log($level, $message);

View File

@ -26,6 +26,7 @@ class MainLogger extends \Thread implements Logger{
protected $logStream;
protected $shutdown;
protected $hasANSI;
protected $logDebug;
private $logResource;
/** @var MainLogger */
public static $logger = null;
@ -33,10 +34,11 @@ class MainLogger extends \Thread implements Logger{
/**
* @param string $logFile
* @param bool $hasANSI
* @param bool $logDebug
*
* @throws \RuntimeException
*/
public function __construct($logFile, $hasANSI = false){
public function __construct($logFile, $hasANSI = false, $logDebug = false){
if(static::$logger instanceof MainLogger){
throw new \RuntimeException("MainLogger has been already created");
}
@ -44,6 +46,7 @@ class MainLogger extends \Thread implements Logger{
@mkdir(basename($logFile), 0777, true);
$this->logFile = $logFile;
$this->hasANSI = (bool) $hasANSI;
$this->logDebug = (bool) $logDebug;
$this->logStream = "";
$this->start(PTHREADS_INHERIT_NONE);
}
@ -56,35 +59,45 @@ class MainLogger extends \Thread implements Logger{
}
public function emergency($message){
$this->send(TextFormat::RED . "[EMERGENCY] ". $message);
$this->send(TextFormat::RED . "[EMERGENCY] " . $message);
}
public function alert($message){
$this->send(TextFormat::RED . "[ALERT] ". $message);
$this->send(TextFormat::RED . "[ALERT] " . $message);
}
public function critical($message){
$this->send(TextFormat::RED . "[CRITICAL] ". $message);
$this->send(TextFormat::RED . "[CRITICAL] " . $message);
}
public function error($message){
$this->send(TextFormat::DARK_RED . "[ERROR] ". $message);
$this->send(TextFormat::DARK_RED . "[ERROR] " . $message);
}
public function warning($message){
$this->send(TextFormat::YELLOW . "[WARNING] ". $message);
$this->send(TextFormat::YELLOW . "[WARNING] " . $message);
}
public function notice($message){
$this->send(TextFormat::AQUA . "[NOTICE] ". $message);
$this->send(TextFormat::AQUA . "[NOTICE] " . $message);
}
public function info($message){
$this->send(TextFormat::WHITE . "[INFO] ". $message);
$this->send(TextFormat::WHITE . "[INFO] " . $message);
}
public function debug($message){
$this->send(TextFormat::GRAY . "[DEBUG] ". $message);
if($this->logDebug === false){
return;
}
$this->send(TextFormat::GRAY . "[DEBUG] " . $message);
}
/**
* @param bool $logDebug
*/
public function setLogDebug($logDebug){
$this->logDebug = (bool) $logDebug;
}
public function log($level, $message){
@ -143,7 +156,7 @@ class MainLogger extends \Thread implements Logger{
while($this->shutdown === false){
if(strlen($this->logStream) >= 4096){
$this->synchronized(function(){
$this->synchronized(function (){
$chunks = strlen($this->logStream) >> 12;
$chunk = substr($this->logStream, 0, $chunks << 12);
$this->logStream = substr($this->logStream, $chunks << 12);

View File

@ -26,6 +26,7 @@ class MainLogger extends \Thread implements Logger{
protected $logStream;
protected $shutdown;
protected $hasANSI;
protected $logDebug;
private $logResource;
/** @var MainLogger */
public static $logger = null;
@ -33,10 +34,11 @@ class MainLogger extends \Thread implements Logger{
/**
* @param string $logFile
* @param bool $hasANSI
* @param bool $logDebug
*
* @throws \RuntimeException
*/
public function __construct($logFile, $hasANSI = false){
public function __construct($logFile, $hasANSI = false, $logDebug = false){
if(static::$logger instanceof MainLogger){
throw new \RuntimeException("MainLogger has been already created");
}
@ -44,6 +46,7 @@ class MainLogger extends \Thread implements Logger{
@mkdir(basename($logFile), 0777, true);
$this->logFile = $logFile;
$this->hasANSI = (bool) $hasANSI;
$this->logDebug = (bool) $logDebug;
$this->logStream = "";
$this->start(PTHREADS_INHERIT_NONE);
}
@ -56,35 +59,45 @@ class MainLogger extends \Thread implements Logger{
}
public function emergency($message){
$this->send(TextFormat::RED . "[EMERGENCY] ". $message);
$this->send(TextFormat::RED . "[EMERGENCY] " . $message);
}
public function alert($message){
$this->send(TextFormat::RED . "[ALERT] ". $message);
$this->send(TextFormat::RED . "[ALERT] " . $message);
}
public function critical($message){
$this->send(TextFormat::RED . "[CRITICAL] ". $message);
$this->send(TextFormat::RED . "[CRITICAL] " . $message);
}
public function error($message){
$this->send(TextFormat::DARK_RED . "[ERROR] ". $message);
$this->send(TextFormat::DARK_RED . "[ERROR] " . $message);
}
public function warning($message){
$this->send(TextFormat::YELLOW . "[WARNING] ". $message);
$this->send(TextFormat::YELLOW . "[WARNING] " . $message);
}
public function notice($message){
$this->send(TextFormat::AQUA . "[NOTICE] ". $message);
$this->send(TextFormat::AQUA . "[NOTICE] " . $message);
}
public function info($message){
$this->send(TextFormat::WHITE . "[INFO] ". $message);
$this->send(TextFormat::WHITE . "[INFO] " . $message);
}
public function debug($message){
$this->send(TextFormat::GRAY . "[DEBUG] ". $message);
if($this->logDebug === false){
return;
}
$this->send(TextFormat::GRAY . "[DEBUG] " . $message);
}
/**
* @param bool $logDebug
*/
public function setLogDebug($logDebug){
$this->logDebug = (bool) $logDebug;
}
public function log($level, $message){
@ -143,7 +156,7 @@ class MainLogger extends \Thread implements Logger{
while($this->shutdown === false){
if(strlen($this->logStream) >= 4096){
$this->synchronized(function(){
$this->synchronized(function (){
$chunks = strlen($this->logStream) >> 12;
$chunk = substr($this->logStream, 0, $chunks << 12);
$this->logStream = substr($this->logStream, $chunks << 12);