PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/Log/LogInit.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 140 lines | 32 code | 18 blank | 90 comment | 8 complexity | 110ed72e51f26ad907aba51418894522 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. * VirtueMart Logging Initialization.
  5. *
  6. * This file is included only once, inside virtuemart_parser.php. External
  7. * applications that run outside of VirtueMart - such as PayPal notification
  8. * (notify.php) should also include this file.
  9. *
  10. * Logging has been modified so that instead of just a single "vmLogger",
  11. * which used to only log to the display, there are now three loggers:
  12. *
  13. * $vmLogger - This used to be the display logger; it is now a composite
  14. * logger that forwards log messages to both the display _and_
  15. * file loggers. Note that the composite logger itself does
  16. * not check message priorities against the logging level; each
  17. * child logger does that itself. This means that the display
  18. * logger can be set to "WARNING" and the file logger can
  19. * be set to "DEBUG". Then, if you do something like:
  20. *
  21. * $vmLogger->debug("This is a debug message.");
  22. *
  23. * ...the message will get logged by the file logger (because
  24. * it's log level is DEBUG), but NOT by the display logger
  25. * (because it's log level is WARNING.)
  26. *
  27. *
  28. * $vmDisplayLogger - The actual display logger. Note that, due to the
  29. * way the display logger is implemented, log messages
  30. * with a priority >PEAR_LOG_DEBUG will always go to
  31. * the display. Debug-priority messages will only be
  32. * shown if the DEBUG option is enabled in the VM admin
  33. * configuration panel. Also, display logging can now
  34. * be restricted by client IP address, also within the
  35. * VM admin configuration panel.
  36. *
  37. *
  38. * $vmFileLogger - The file logger. Note that, if file logging is
  39. * disabled, a "null" logger will be instantiated in
  40. * it's place. This is so that code using vmFileLogger
  41. * will continue to function without error, and without
  42. * having to actually test if the file logger is enabled.
  43. *
  44. * If file logging is enabled, but the logger cannot be
  45. * created, then a message will be written to the
  46. * display (using the vmDisplayLogger), and then a
  47. * "null" logger will be created in it's place (for the
  48. * same reason as noted above.)
  49. *
  50. * The log file can be enabled/disabled via the VM admin
  51. * config panel; this is also where the log file name is
  52. * specified, along with the log level and formatting
  53. * options (such as inclusion of remote IP address,
  54. * username [if logged in], and VM session ID.)
  55. *
  56. * Note that, by my reasoning, pretty much all logging output intended for
  57. * the display should also go to the file. So, you would normally use
  58. * $vmLogger instead of just $vmDisplayLogger.
  59. * However, there are many cases where you would only want to log to
  60. * file and not have the output go to display. In these cases, you would
  61. * use the $vmFileLogger.
  62. *
  63. * All three loggers are available via $GLOBALS[] as:
  64. *
  65. * $GLOBALS['vmLogger'] //The composite logger
  66. * $GLOBALS['vmDisplayLogger'] //The display logger
  67. * $GLOBALS['vmFileLogger'] //The file logger
  68. *
  69. *
  70. * @version $Id: LogInit.php 1215 2008-02-05 12:14:19Z soeren_nb $
  71. * @package VirtueMart
  72. * @subpackage Log
  73. * @author Mike Mills (mike@MikeMillsConsulting.com)
  74. * @copyright Copyright (C) 2008 Mike Mills. All rights reserved.
  75. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  76. * VirtueMart is free software. This version may have been modified pursuant
  77. * to the GNU General Public License, and as distributed it includes or
  78. * is derivative of works licensed under the GNU General Public License or
  79. * other free or open source software licenses.
  80. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  81. *
  82. * http://virtuemart.net
  83. */
  84. require_once(CLASSPATH."Log/Log.php");
  85. require_once(CLASSPATH."Log/composite.php");
  86. require_once(CLASSPATH."Log/display.php");
  87. require_once(CLASSPATH."Log/file.php");
  88. $vmLogger = null;
  89. $vmDisplayLogger = null;
  90. $vmFileLogger = null;
  91. /* The $vmLogIdentifier is intended to separate different sources of logging
  92. information - such as VirtueMart itself, or external apps like the PayPal
  93. notification script (notify.php).
  94. */
  95. if(!isset($vmLogIdentifier))
  96. $vmLogIdentifier = '';
  97. /* The existing display logger starts out with a log level of PEAR_LOG_TIP.
  98. However, no debug-levwel output will be sent to the display unless the DEBUG
  99. option is turned on inside the VM admin configuration panel. */
  100. $vmDisplayLoggerConf = array( 'buffering' => true );
  101. $vmDisplayLogger = &vmLog::singleton('display', '', $vmLogIdentifier, $vmDisplayLoggerConf, PEAR_LOG_TIP);
  102. /* Use a null logger if file logging is disabled or if there is an error. This
  103. is so that code using the logger will continue to work without problem. */
  104. if(VM_LOGFILE_ENABLED != '1')
  105. $vmFileLogger = &vmLog::singleton('null');
  106. else {
  107. $vmFileLoggerConf = array('mode' => 0600, 'timeFormat' => '%X %x', 'lineFormat' => VM_LOGFILE_FORMAT);
  108. $vmFileLogger = &vmLog::singleton('file', VM_LOGFILE_NAME, $vmLogIdentifier, $vmFileLoggerConf, vmLog::stringToPriorityPEAR(VM_LOGFILE_LEVEL));
  109. if($vmFileLogger == false)
  110. {
  111. $vmDisplayLogger->warning($VM_LANG->_VM_ADMIN_CFG_LOGFILE_ERROR);
  112. $vmFileLogger = &vmLog::singleton('null');
  113. }
  114. }
  115. $vmLogger = &vmLog::singleton('composite');
  116. $vmLogger->addChild($vmDisplayLogger);
  117. $vmLogger->addChild($vmFileLogger);
  118. $vmLogger->open();
  119. $GLOBALS['vmLogger'] =& $vmLogger;
  120. $GLOBALS['vmDisplayLogger'] =& $vmDisplayLogger;
  121. $GLOBALS['vmFileLogger'] =& $vmFileLogger;
  122. ?>