Log.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. $GLOBALS['API_TEST'] = true;
  8. /**
  9. * Description of Log
  10. *
  11. * @author jgao
  12. */
  13. class Log {
  14. //put your code here
  15. static function dtCurrent(){
  16. return date('Y-m-d ').(date('H') + 8).date(':i:s');
  17. }
  18. /**
  19. * 浏览器打印调试信息
  20. * @param type $msg
  21. */
  22. static function debug($msg){
  23. if($GLOBALS['API_TEST']){
  24. echo('['.self::dtCurrent().']|'.$msg.'</br>');
  25. }
  26. }
  27. /**
  28. * 浏览器输出对象信息
  29. * @param type $obj
  30. */
  31. static function console($obj){
  32. self::debug(json_encode($obj));
  33. }
  34. /**
  35. * 浏览器弹窗提示
  36. * @param type $msg
  37. */
  38. static function alert($msg){
  39. if($GLOBALS['API_TEST']){
  40. echo "<Script language=\"javascript\">alert(\"".$msg."\");</Script>";
  41. }
  42. }
  43. /**
  44. * 写日志文件
  45. * 注意:这里必须写入CEE指定的日志目录!!
  46. * Ps.CEE 目录: dirname(__FILE__)."/../../../../logs/".date("Ynj").".log";
  47. * @param type $msg
  48. */
  49. static function output($msg){
  50. $fileName = "";
  51. if(GAME_ONLINE){
  52. $fileName = dirname(__FILE__)."/../../../../logs/".date("Ynj").".log"; //cee目录
  53. }else{
  54. $fileName = dirname(__FILE__)."/../AppLog/".date("Ynj").".log";
  55. }
  56. $fd = fopen($fileName,"a+");
  57. fputs($fd,"[".self::dtCurrent()."]|".json_encode($msg)."\r\n");
  58. fclose($fd);
  59. }
  60. }