WindowsAzure.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Zend Framework
  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.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_WindowsAzure
  17. * @subpackage Storage
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Log_Formatter_Interface
  24. */
  25. require_once 'Zend/Log/Formatter/Interface.php';
  26. /**
  27. * @see Zend_Service_WindowsAzure_Storage_DynamicTableEntity
  28. */
  29. require_once 'Zend/Service/WindowsAzure/Storage/DynamicTableEntity.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Service_WindowsAzure
  33. * @subpackage Log
  34. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Service_WindowsAzure_Log_Formatter_WindowsAzure
  38. implements Zend_Log_Formatter_Interface
  39. {
  40. /**
  41. * Write a message to the table storage
  42. *
  43. * @param array $event
  44. *
  45. * @return Zend_Service_WindowsAzure_Storage_DynamicTableEntity
  46. */
  47. public function format($event)
  48. {
  49. // partition key is the current date, represented as YYYYMMDD
  50. // row key will always be the current timestamp. These values MUST be hardcoded.
  51. $logEntity = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
  52. date('Ymd'), microtime(true)
  53. );
  54. // Windows Azure automatically adds the timestamp, but the timezone is most of the time
  55. // different compared to the origin server's timezone, so add this timestamp aswell.
  56. $event['server_timestamp'] = $event['timestamp'];
  57. unset($event['timestamp']);
  58. foreach ($event as $key => $value) {
  59. if ((is_object($value) && !method_exists($value, '__toString'))
  60. || is_array($value)
  61. ) {
  62. $value = gettype($value);
  63. }
  64. $logEntity->{$key} = $value;
  65. }
  66. return $logEntity;
  67. }
  68. }