eventlog.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by the Free Pascal development team
  4. Unix implementation of event mechanism
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$linklib c}
  12. const
  13. // OpenLog options
  14. LOG_PID = $01;
  15. LOG_CONS = $02;
  16. LOG_ODELAY = $04;
  17. LOG_NDELAY = $08;
  18. LOG_NOWAIT = $10;
  19. LOG_PERROR = $20;
  20. // Priority levels
  21. LOG_EMERG = 0;
  22. LOG_ALERT = 1;
  23. LOG_CRIT = 2;
  24. LOG_ERR = 3;
  25. LOG_WARNING = 4;
  26. LOG_NOTICE = 5;
  27. LOG_INFO = 6;
  28. LOG_DEBUG = 7;
  29. LOG_PRIMASK = $07;
  30. // facility
  31. LOG_KERN = 0 shl 3;
  32. LOG_USER = 1 shl 3;
  33. LOG_MAIL = 2 shl 3;
  34. LOG_DAEMON = 3 shl 3;
  35. LOG_AUTH = 4 shl 3;
  36. LOG_SYSLOG = 5 shl 3;
  37. LOG_LPR = 6 shl 3;
  38. LOG_NEWS = 7 shl 3;
  39. LOG_UUCP = 8 shl 3;
  40. LOG_CRON = 9 shl 3;
  41. LOG_AUTHPRIV = 10 shl 3;
  42. procedure closelog;cdecl;external;
  43. procedure openlog(__ident:pchar; __option:longint; __facilit:longint);cdecl;external;
  44. function setlogmask(__mask:longint):longint;cdecl;external;
  45. procedure syslog(__pri:longint; __fmt:pchar; args:array of const);cdecl;external;
  46. Function TEventLog.DefaultFileName : String;
  47. begin
  48. Result:='/tmp/'+ChangeFileExt(ExtractFileName(Paramstr(0)),'.log');
  49. end;
  50. Resourcestring
  51. SErrNoSysLog = 'Could not open system log (error %d)';
  52. SErrLogFailed = 'Failed to log entry (error %d)';
  53. Procedure TEventLog.ActivateSystemLog;
  54. begin
  55. CheckIdentification;
  56. OpenLog(Pchar(Identification),LOG_NOWAIT,LOG_USER);
  57. end;
  58. Procedure TEventLog.DeActivateSystemLog;
  59. begin
  60. CloseLog;
  61. end;
  62. procedure TEventLog.WriteSystemLog(EventType : TEventType; Msg : String);
  63. Var
  64. P,PT : PChar;
  65. T : String;
  66. begin
  67. P:=PChar(Msg);
  68. T:=EventTypeToString(EventType);
  69. PT:=PChar(T);
  70. syslog(MapTypeToEvent(EventType),'[%s] %s',[PT,P]);
  71. end;
  72. Function TEventLog.RegisterMessageFile(AFileName : String) : Boolean;
  73. begin
  74. Result:=True;
  75. end;
  76. function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
  77. begin
  78. Result:=0;
  79. If (EventType=ETCustom) then
  80. DoGetCustomEventCategory(Result);
  81. end;
  82. function TEventLog.MapTypeToEventID(EventType: TEventType): DWord;
  83. begin
  84. Result:=0;
  85. If (EventType=ETCustom) then
  86. DoGetCustomEventID(Result);
  87. end;
  88. function TEventLog.MapTypeToEvent(EventType: TEventType): DWord;
  89. Const
  90. WinET : Array[TEventType] of word = (LOG_NOTICE,
  91. LOG_INFO,LOG_WARNING,LOG_ERR,LOG_DEBUG);
  92. begin
  93. If EventType=etCustom Then
  94. begin
  95. If CustomLogType=0 then
  96. CustomLogType:=LOG_NOTICE;
  97. Result:=CustomLogType;
  98. DoGetCustomEvent(Result);
  99. end
  100. else
  101. Result:=WinET[EventType];
  102. end;