log.tin 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 模块名称:日志模块
  4. 模块说明:本文件属于框架代码的一部分,不建议修改。如有需求请在 GitHub 发 issue 或者 PR
  5. 版权声明:本文件属于 PaoTin++ 的一部分
  6. ===========
  7. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  8. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  9. ===========
  10. */
  11. #var gLog[buffer] {buffer.log};
  12. #var gLog[socket] {socket.log};
  13. #var gLog[info] {info.log};
  14. #var gLog[ok] {ok.log};
  15. #var gLog[warn] {warn.log};
  16. #var gLog[error] {error.log};
  17. #var gLog[debug] {debug.log};
  18. #var gLog[PATH] {log};
  19. #var gLog[initialled] {false};
  20. #func {InitLog} {
  21. #local path {%1};
  22. #if { @existsDir{var} } {
  23. #var gLog[PATH] {var/log};
  24. };
  25. #else {
  26. #var gLog[PATH] {log};
  27. };
  28. #if { !@mkdir{$gLog[PATH]/$path} } {
  29. #return 0;
  30. };
  31. #var gLog[PATH] {$gLog[PATH]/$path};
  32. #var gLog[initialled] {true};
  33. option.Define {DebugLog} {Bool} {是否开启调试日志} {false};
  34. option.Define {DebugLogEcho} {Bool} {是否显示调试日志} {false};
  35. option.Define {DebugTags} {Slist} {记录调试日志的 tag 列表} {};
  36. option.Define {EchoCommand} {Bool} {是否回显发送的命令} {false};
  37. #return 1;
  38. };
  39. #alias {mudLog} {
  40. #if { "%0" == "%c> {$TELNET[GA]|$TELNET[EOR]}" } {
  41. #local cmd {@str.Trim{$gXttPipeLine[1]}};
  42. #if { &gXttPipeLine[] <= 1 } {
  43. log.write {$gLog[socket]} {%0(<259>$cmd<299>)(<239>EMPTY<299>)};
  44. };
  45. #else {
  46. log.write {$gLog[socket]} {%0(<259>$cmd<299>)};
  47. };
  48. };
  49. #else {
  50. log.write {$gLog[socket]} {%0};
  51. };
  52. };
  53. #alias {okLog} {log.write {$gLog[ok]} {<129>%0} {ECHO}};
  54. #alias {warnLog} {log.write {$gLog[warn]} {<139>%0} {ECHO}};
  55. #alias {errLog} {log.write {$gLog[error]} {<119>%0} {ECHO}};
  56. #alias {infoLog} {log.write {$gLog[info]} {%0} {ECHO}};
  57. #alias {dbgLog} {
  58. #local tag {%1};
  59. #if { @option.IsDisable{DebugLog} } {
  60. #return;
  61. };
  62. #local echo {};
  63. #if { @option.IsEnable{DebugLogEcho} } {
  64. #local echo {ECHO};
  65. };
  66. #if { @slist.Contains{{@option.Get{DebugTags}};$tag} } {
  67. log.write {$gLog[debug]} {<850>%0<999>} {$echo};
  68. };
  69. };
  70. #alias {noLog} {#0};
  71. #alias {{[a-z]{1,10}}Log %*} {
  72. #local logName {};
  73. #format logName {%l} {%1};
  74. log.write {${logName}.log} {%2};
  75. };
  76. #alias {log.write} {
  77. #local file {%1};
  78. #local text {%2};
  79. #local echo {%3};
  80. #if { "$gLog[initialled]" != "true" } {#return};
  81. #line logmode stamp #line log {$gLog[PATH]/$file} {$text<099>};
  82. #if { "$echo" == "ECHO" } {
  83. #echo {%s} {$text<099>};
  84. };
  85. };
  86. #alias {log.Open} {
  87. #if { "$gLog[initialled]" != "true" } {#return};
  88. #config {LOG} {RAW};
  89. #config {LOG LEVEL} {HIGH};
  90. #log timestamp {%Y-%m-%d %H:%M:%S };
  91. #log append {$gLog[PATH]/$gLog[buffer]};
  92. ttevent.Handle {RECEIVED INPUT} {log} {framework/log} {log.input};
  93. ttevent.Handle {RECEIVED LINE} {log} {framework/log} {mudLog $gTTEventArgZero};
  94. ttevent.Handle {SEND OUTPUT} {log} {framework/log} {log.sendLog};
  95. };
  96. #alias {log.input} {
  97. #if { "$gLog[initialled]" != "true" } {#return};
  98. #local needEcho {false};
  99. #if @option.IsDisable{EchoCommand} {
  100. #local needEcho {true};
  101. };
  102. #else {
  103. #line sub escape #var tmp {$gTTEventArgZero};
  104. #local cmds {};
  105. #list cmds create {$tmp};
  106. #if { &cmds[] > 1 } {
  107. #local needEcho {true};
  108. };
  109. };
  110. #if { "$needEcho" == "true" } {
  111. #local input {$gTTEventArgZero};
  112. #replace input {<} {\<};
  113. #echo {<029>%t INPUT: <429>%s<099>} {%Y-%m-%d %H:%M:%S} {$input};
  114. };
  115. };
  116. #alias {log.sendLog} {
  117. #local text {$gTTEventArgZero};
  118. #replace text {<} {\<};
  119. #format text {<029>SEND: <429>%p<099>} {$text};
  120. mudLog $text;
  121. #if @option.IsEnable{EchoCommand} {
  122. #echo {<029>%t %s} {%Y-%m-%d %H:%M:%S} {$text};
  123. };
  124. };