eventlog.inc 2.9 KB

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