Hoa central
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | Static Private Attributes | List of all members
Hoa\Log\Log Class Reference
Inheritance diagram for Hoa\Log\Log:

Public Member Functions

 accept ($filter)
 
 acceptAll ()
 
 setFilter ($filter)
 
 drop ($filter)
 
 dropAll ()
 
 addStackInformations (Array $stackInfos)
 
 addStackInformation ($key, $value)
 
 getAddedStackInformations ()
 
 log ($message, $type=self::DEBUG, $extra=array())
 
 getFilters ()
 
 getBacktrace ()
 
 getLogStack ()
 
 typeAsString ($type)
 
 __toString ()
 

Static Public Member Functions

static getChannel ($id=null)
 

Public Attributes

const EMERGENCY = 1
 
const ALERT = 2
 
const CRITICAL = 4
 
const ERROR = 8
 
const WARNING = 16
 
const NOTICE = 32
 
const INFORMATIONAL = 64
 
const DEBUG = 128
 
const TEST = 256
 
const STACK_TIMESTAMP = 'timestamp'
 
const STACK_MESSAGE = 'message'
 
const STACK_PRIORITY = 'priority'
 
const STACK_MEMORY = 'memory'
 
const STACK_MEMORY_PEAK = 'memory_peak'
 

Protected Attributes

 $_stack = array()
 
 $_backtrace = null
 
 $_filters = null
 
 $_stackInfos = array()
 

Private Member Functions

 __construct ()
 

Static Private Attributes

static $_instances = null
 
static $_currentId = null
 

Detailed Description

Class .

Propose a log system.

Author
Ivan Enderlin ivan..nosp@m.ende.nosp@m.rlin@.nosp@m.hoa-.nosp@m.proje.nosp@m.ct.n.nosp@m.et

Definition at line 70 of file Log.php.

Constructor & Destructor Documentation

Hoa\Log\Log::__construct ( )
private

Build a new log system.

private

Returns
void

Definition at line 222 of file Log.php.

222  {
223 
224  return;
225  }

Member Function Documentation

Hoa\Log\Log::__toString ( )

Transform the log into a string.

public

Returns
string

Definition at line 516 of file Log.php.

516  {
517 
518  return $this->getBacktrace()->__toString();
519  }
520 }
521 
522 }
523 
524 namespace {
525 
536 if(!function_exists('hlog')) {
537 function hlog ( $message, $type = \Hoa\Log::DEBUG, $extra = array() ) {
538 
539  return \Hoa\Log::getChannel()->log($message, $type, $extra);
540 }}
getBacktrace()
Definition: Log.php:446
const DEBUG
Definition: Log.php:128

Here is the call graph for this function:

Hoa\Log\Log::accept (   $filter)

Accept a type of log on the outputstream.

public

Parameters
int$filterA filter (please, see the class constants).
Returns
int

Definition at line 265 of file Log.php.

265  {
266 
267  if(null === $this->_filters)
268  return $this->_filters = $filter;
269 
270  $old = $this->_filters;
271  $this->_filters = $old | $filter;
272 
273  return $old;
274  }
Hoa\Log\Log::acceptAll ( )

Accept all types of logs on the outputstream.

public

Returns
int

Definition at line 282 of file Log.php.

282  {
283 
284  $old = $this->_filters;
285  $this->_filters = null;
286 
287  return $old;
288  }
Hoa\Log\Log::addStackInformation (   $key,
  $value 
)

Add an extra stack information.

public

Parameters
string$keyInformation name.
string$valueInformation value.
Returns
array

Definition at line 365 of file Log.php.

365  {
366 
367  $this->_stackInfos[$key] = $value;
368 
369  return $this->getAddedStackInformations();
370  }
getAddedStackInformations()
Definition: Log.php:378

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Log\Log::addStackInformations ( Array  $stackInfos)

Add extra stack informations.

public

Parameters
array$stackInfosStack informations.
Returns
array

Definition at line 349 of file Log.php.

349  {
350 
351  foreach($stackInfos as $key => $value)
352  $this->addStackInformation($key, $value);
353 
354  return $this->getAddedStackInformations();
355  }
addStackInformation($key, $value)
Definition: Log.php:365
getAddedStackInformations()
Definition: Log.php:378

Here is the call graph for this function:

Hoa\Log\Log::drop (   $filter)

Drop a type of log on the outputstream.

public

Parameters
int$filterA filter (please, see the class constants).
Returns
int

Definition at line 312 of file Log.php.

312  {
313 
314  $old = $this->_filters;
315  $this->_filters = $old & ~$filter;
316 
317  return $old;
318  }
Hoa\Log\Log::dropAll ( )

Drop all type of logs on the outputstreams.

public

Returns
int

Definition at line 326 of file Log.php.

326  {
327 
328  $old = $this->_filters;
329  $this->_filters = self::EMERGENCY
330  & self::ALERT
331  & self::CRITICAL
332  & self::ERROR
333  & self::WARNING
334  & self::NOTICE
335  & self::INFORMATIONAL
336  & self::DEBUG
337  & self::TEST;
338 
339  return $old;
340  }
Hoa\Log\Log::getAddedStackInformations ( )

Get extra stack informations.

public

Returns
array

Definition at line 378 of file Log.php.

378  {
379 
380  return $this->_stackInfos;
381  }
$_stackInfos
Definition: Log.php:212

Here is the caller graph for this function:

Hoa\Log\Log::getBacktrace ( )

Get the backtrace tree.

public

Returns
array

Definition at line 446 of file Log.php.

446  {
447 
448  return $this->_backtrace;
449  }
$_backtrace
Definition: Log.php:198

Here is the caller graph for this function:

static Hoa\Log\Log::getChannel (   $id = null)
static

Make a multiton.

public

Parameters
string$idChannel ID (i.e. singleton ID)
Returns
Exceptions

Definition at line 235 of file Log.php.

235  {
236 
237  if(null === self::$_currentId && null === $id)
238  throw new Exception(
239  'Must precise a singleton index once.', 0);
240 
241  if(!isset(self::$_instances[$id])) {
242 
243  self::$_instances[$id] = new self();
244  \Hoa\Core\Event::register(
245  'hoa://Event/Log/' . $id,
246  self::$_instances[$id]
247  );
248  }
249 
250  if(null !== $id)
251  self::$_currentId = $id;
252 
253  $handle = self::$_instances[self::$_currentId];
254 
255  return $handle;
256  }
Hoa\Log\Log::getFilters ( )

Get filters.

protected

Returns
int

Definition at line 435 of file Log.php.

435  {
436 
437  return $this->_filters;
438  }

Here is the caller graph for this function:

Hoa\Log\Log::getLogStack ( )

Get the log stack.

public

Returns
array

Definition at line 457 of file Log.php.

457  {
458 
459  return $this->_stack;
460  }
Hoa\Log\Log::log (   $message,
  $type = self::DEBUG,
  $extra = array() 
)

Log a message with a type.

public

Parameters
string$messageThe log message.
int$typeType of message (please, see the class constants).
array$extraExtra dynamic informations.
Returns
void

Definition at line 393 of file Log.php.

393  {
394 
395  $filters = $this->getFilters();
396 
397  if(null !== $filters && !($type & $filters))
398  return;
399 
400  $handle = $this->_stack[] = array_merge(
401  array(
402  self::STACK_TIMESTAMP => microtime(true),
403  self::STACK_MESSAGE => $message,
404  self::STACK_PRIORITY => $type,
405  self::STACK_MEMORY => memory_get_usage(),
406  self::STACK_MEMORY_PEAK => memory_get_peak_usage()
407  ),
408  $this->getAddedStackInformations(),
409  $extra
410  );
411 
412  \Hoa\Core\Event::notify(
413  'hoa://Event/Log/' . self::$_currentId,
414  $this,
415  new \Hoa\Core\Event\Bucket(array('log' => $handle))
416  );
417 
418  if($type & self::DEBUG) {
419 
420  if(null === $this->_backtrace)
421  $this->_backtrace = new Backtrace();
422 
423  $this->_backtrace->debug();
424  }
425 
426  return;
427  }
getFilters()
Definition: Log.php:435
getAddedStackInformations()
Definition: Log.php:378

Here is the call graph for this function:

Hoa\Log\Log::setFilter (   $filter)

Set filters directly.

public

Parameters
int$filterA filter (please, see the class constants).
Returns
int

Definition at line 297 of file Log.php.

297  {
298 
299  $old = $this->_filters;
300  $this->_filters = $filter;
301 
302  return $old;
303  }
Hoa\Log\Log::typeAsString (   $type)

Transform a log type into a string.

public

Parameters
int$typeLog type (please, see the class constants).
Returns
string

Definition at line 469 of file Log.php.

469  {
470 
471  switch($type) {
472 
473  case self::EMERGENCY:
474  return 'EMERGENCY';
475  break;
476 
477  case self::ALERT:
478  return 'ALERT';
479  break;
480 
481  case self::CRITICAL:
482  return 'CRITICAL';
483  break;
484 
485  case self::ERROR:
486  return 'ERROR';
487  break;
488 
489  case self::WARNING:
490  return 'WARNING';
491  break;
492 
493  case self::NOTICE:
494  return 'NOTICE';
495  break;
496 
497  case self::INFORMATIONAL:
498  return 'INFORMATIONAL';
499  break;
500 
501  case self::DEBUG:
502  return 'DEBUG';
503  break;
504 
505  default:
506  return 'unknown';
507  }
508  }

Member Data Documentation

Hoa\Log\Log::$_backtrace = null
protected

Definition at line 198 of file Log.php.

Hoa\Log\Log::$_currentId = null
staticprivate

Definition at line 184 of file Log.php.

Hoa\Log\Log::$_filters = null
protected

Definition at line 205 of file Log.php.

Hoa\Log\Log::$_instances = null
staticprivate

Definition at line 177 of file Log.php.

Hoa\Log\Log::$_stack = array()
protected

Definition at line 191 of file Log.php.

Hoa\Log\Log::$_stackInfos = array()
protected

Definition at line 212 of file Log.php.

const Hoa\Log\Log::ALERT = 2

Priority: alert, action must be taken immediately.

int

Definition at line 86 of file Log.php.

const Hoa\Log\Log::CRITICAL = 4

Priority: critical, critical conditions.

int

Definition at line 93 of file Log.php.

const Hoa\Log\Log::DEBUG = 128

Priority: debug-level messages.

int

Definition at line 128 of file Log.php.

const Hoa\Log\Log::EMERGENCY = 1

Priority: emergency, system is unusable. (Note: priorities from “The BSD Syslog Protocol” (RFC 3164, 4.1.1 PRI Part).

int

Definition at line 79 of file Log.php.

const Hoa\Log\Log::ERROR = 8

Priority: error, error conditions.

int

Definition at line 100 of file Log.php.

const Hoa\Log\Log::INFORMATIONAL = 64

Priority: informational messages.

int

Definition at line 121 of file Log.php.

const Hoa\Log\Log::NOTICE = 32

Priority: notice, normal but significant condition.

int

Definition at line 114 of file Log.php.

const Hoa\Log\Log::STACK_MEMORY = 'memory'

Stack index: memory.

string

Definition at line 163 of file Log.php.

const Hoa\Log\Log::STACK_MEMORY_PEAK = 'memory_peak'

Stack index: memory peak.

string

Definition at line 170 of file Log.php.

const Hoa\Log\Log::STACK_MESSAGE = 'message'

Stack index: message.

string

Definition at line 149 of file Log.php.

const Hoa\Log\Log::STACK_PRIORITY = 'priority'

Stack index: priority.

string

Definition at line 156 of file Log.php.

const Hoa\Log\Log::STACK_TIMESTAMP = 'timestamp'

Stack index: timestamp.

string

Definition at line 142 of file Log.php.

const Hoa\Log\Log::TEST = 256

Priority: test messages.

int

Definition at line 135 of file Log.php.

const Hoa\Log\Log::WARNING = 16

Priority: warning, warning conditions.

int

Definition at line 107 of file Log.php.


The documentation for this class was generated from the following file: