CLog.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec\helpers;
  10. use Yii;
  11. # 本功能使用前,需要配置log
  12. # 参看地址:http://blog.csdn.net/terry_water/article/details/51250478
  13. # 没有配置前,本功能不能使用。
  14. /**
  15. * @author Terry Zhao <2358269014@qq.com>
  16. * @since 1.0
  17. */
  18. class CLog
  19. {
  20. # 1.数据库Log ,将错误信息输出到表:system_log
  21. # common\config\main.php
  22. public static function dbinfo($info,$categories = 'db_mysql'){
  23. $info = self::getInfo($info));
  24. if($info && $categories)
  25. \Yii::info($info,$categories);
  26. }
  27. # 2.文件Log,详细的输出路径参看配置。
  28. # 目前的输出地址为:@app/runtime/logs/file_log.log
  29. public static function fileinfo($info,$categories = 'file_log'){
  30. $info = self::getInfo($info));
  31. if($info && $categories)
  32. \Yii::info($info,$categories);
  33. }
  34. # 3.信息的转换,将object,array 转换成字符串,以供输出。
  35. public static function getInfo($info){
  36. if(!$info)
  37. return false;
  38. if(is_object($info))
  39. $info = CFunc::object_to_array($info);
  40. if(is_array($info))
  41. $info = json_encode($info);
  42. return $info;
  43. }
  44. }