log.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
  4. Original C++ version by Glenn Fiedler ([email protected])
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. }
  17. {$IFDEF PTC_LOGGING}
  18. Const
  19. LOG_create : Boolean = True;
  20. LOG_enabled : Boolean =
  21. {$IFDEF DEBUG}
  22. True;
  23. {$ELSE DEBUG}
  24. False;
  25. {$ENDIF DEBUG}
  26. Var
  27. LOG_file : Text;
  28. Procedure LOG_open;
  29. Begin
  30. ASSignFile(LOG_file, 'ptc.log');
  31. If LOG_create Then
  32. Begin
  33. Rewrite(LOG_file);
  34. Writeln(LOG_file, '[log start]');
  35. LOG_create := False;
  36. End
  37. Else
  38. Append(LOG_file);
  39. End;
  40. Procedure LOG_close;
  41. Begin
  42. CloseFile(LOG_file);
  43. End;
  44. Procedure LOG(message : String);
  45. Begin
  46. If Not LOG_enabled Then
  47. Exit;
  48. LOG_open;
  49. Writeln(LOG_file, message);
  50. LOG_close;
  51. End;
  52. Procedure LOG(message : String; data : Boolean);
  53. Begin
  54. If Not LOG_enabled Then
  55. Exit;
  56. LOG_open;
  57. Write(LOG_file, message, ' = ');
  58. If data Then
  59. Writeln(LOG_file, 'true')
  60. Else
  61. Writeln(LOG_file, 'false');
  62. LOG_close;
  63. End;
  64. Procedure LOG(message : String; data : Integer);
  65. Begin
  66. If Not LOG_enabled Then
  67. Exit;
  68. LOG_open;
  69. Writeln(LOG_file, message, ' = ', data);
  70. LOG_close;
  71. End;
  72. Procedure LOG(message : String; data : Double);
  73. Begin
  74. If Not LOG_enabled Then
  75. Exit;
  76. LOG_open;
  77. Writeln(LOG_file, message, ' = ', data);
  78. LOG_close;
  79. End;
  80. Procedure LOG(message : String; data : String);
  81. Begin
  82. If Not LOG_enabled Then
  83. Exit;
  84. LOG_open;
  85. Writeln(LOG_file, message, ' = ', data);
  86. LOG_close;
  87. End;
  88. Procedure LOG(message : String; data : TPTCFormat);
  89. Begin
  90. If Not LOG_enabled Then
  91. Exit;
  92. LOG_open;
  93. Write(LOG_file, message, ' = Format(');
  94. If data = Nil Then
  95. Write(LOG_file, 'NIL')
  96. Else
  97. Begin
  98. Write(LOG_file, data.bits:2);
  99. If data.direct Then
  100. Begin
  101. Write(LOG_file, ',$', HexStr(data.r, 8), ',$', HexStr(data.g, 8), ',$', HexStr(data.b, 8));
  102. If data.a <> 0 Then
  103. Write(LOG_file, ',$', HexStr(data.a, 8));
  104. End;
  105. End;
  106. Writeln(LOG_file, ')');
  107. LOG_close;
  108. End;
  109. Procedure LOG(message : String; data : TPTCError);
  110. Begin
  111. If Not LOG_enabled Then
  112. Exit;
  113. LOG_open;
  114. Writeln(LOG_file, message, ': ', data.message);
  115. LOG_close;
  116. End;
  117. {$ELSE PTC_LOGGING}
  118. {$DEFINE LOG:=//}
  119. {$ENDIF PTC_LOGGING}