PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/source/innomatic/core/classes/innomatic/logging/LogCenter.php

https://bitbucket.org/innoteam/innomatic
PHP | 112 lines | 53 code | 12 blank | 47 comment | 11 complexity | 8ec9166592fc84a9f6876e52bd9ae971 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, LGPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Innomatic
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.
  9. *
  10. * @copyright 1999-2012 Innoteam S.r.l.
  11. * @license http://www.innomatic.org/license/ BSD License
  12. * @link http://www.innomatic.org
  13. * @since Class available since Release 5.0
  14. */
  15. require_once('innomatic/logging/Logger.php');
  16. /*!
  17. @class LogCenter
  18. @abstract Automatic logging of events in multiple logs.
  19. */
  20. class LogCenter {
  21. /*! @public mApplication string - Application id name. */
  22. private $mApplication;
  23. /*!
  24. @function LogCenter
  25. @abstract Class constructor.
  26. */
  27. public function LogCenter($application = '') {
  28. $this->mApplication = $application;
  29. }
  30. /*!
  31. @function LogEvent
  32. @abstract Logs an event
  33. @param destinations array - Array of the destination logs. Available keys: root, rootda,
  34. webservices, php, application, domain, domainda.
  35. @param context string - Event context.
  36. @param eventString string - String to be logged.
  37. @param eventType integer - Type of log event.
  38. @param die boolean - True if Innomatic must die after logging the event.
  39. @result Always true
  40. */
  41. public function logEvent($destinations, $context, $eventString, $eventType = Logger::GENERIC, $die = false) {
  42. // Root
  43. //
  44. if (isset($destinations['root'])) {
  45. $tmp_log = InnomaticContainer::instance('innomaticcontainer')->getLogger();
  46. $tmp_log->logEvent($context, $eventString, $eventType);
  47. unset($tmp_log);
  48. }
  49. // Root db
  50. //
  51. if (isset($destinations['rootda'])) {
  52. $tmp_log = new Logger(InnomaticContainer::instance('innomaticcontainer')->getHome().'core/log/innomatic_root_db.log');
  53. $tmp_log->logEvent($context, $eventString, $eventType);
  54. unset($tmp_log);
  55. }
  56. // Web services
  57. //
  58. if (isset($destinations['webservices'])) {
  59. $tmp_log = new Logger(InnomaticContainer::instance('innomaticcontainer')->getHome().'core/log/webservices.log');
  60. $tmp_log->logEvent($context, $eventString, $eventType);
  61. unset($tmp_log);
  62. }
  63. // PHP
  64. //
  65. if (isset($destinations['php'])) {
  66. if (InnomaticContainer::instance('innomaticcontainer')->getState() != InnomaticContainer::STATE_SETUP) {
  67. $php_log = InnomaticContainer::instance('innomaticcontainer')->getHome().'core/log/php.log';
  68. } else {
  69. $php_log = InnomaticContainer::instance('innomaticcontainer')->getHome().'core/log/innomatic.log';
  70. }
  71. $tmp_log = new Logger($php_log);
  72. $tmp_log->logEvent($context, $eventString, $eventType);
  73. unset($tmp_log);
  74. }
  75. // Application
  76. //
  77. if (isset($destinations['application']) and is_dir(InnomaticContainer::instance('innomaticcontainer')->getHome().'core/applications/'.$this->mApplication)) {
  78. $tmp_log = new Logger(InnomaticContainer::instance('innomaticcontainer')->getHome().'core/applications/'.$this->mApplication.'/application.log');
  79. $tmp_log->logEvent($context, $eventString, $eventType);
  80. unset($tmp_log);
  81. }
  82. // Domain
  83. //
  84. if (isset($destinations['domain'])) {
  85. $tmp_log = new Logger(InnomaticContainer::instance('innomaticcontainer')->getHome().'core/domains/'.InnomaticContainer::instance('innomaticcontainer')->getCurrentDomain()->domaindata['domainid'].'/log/domain.log');
  86. $tmp_log->logEvent($context, $eventString, $eventType);
  87. unset($tmp_log);
  88. }
  89. // Domain dataaccess
  90. //
  91. if (isset($destinations['domainda'])) {
  92. $tmp_log = new Logger(InnomaticContainer::instance('innomaticcontainer')->getHome().'core/domains/'.InnomaticContainer::instance('innomaticcontainer')->getCurrentDomain()->domaindata['domainid'].'/logs/dataaccess.log');
  93. $tmp_log->logEvent($context, $eventString, $eventType);
  94. unset($tmp_log);
  95. }
  96. if ($die)
  97. InnomaticContainer::instance('innomaticcontainer')->abort($eventString);
  98. return true;
  99. }
  100. }