File: logging_mod_win.cpp

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (101 lines) | stat: -rw-r--r-- 2,498 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
   FALCON - The Falcon Programming Language
   FILE: logging_mod_win.cpp

   Logging module -- module service classes (MS-Windows specific)
   -------------------------------------------------------------------
   Author: Giancarlo Niccolai
   Begin: Sat, 05 Sep 2009 17:21:00 +0200

   -------------------------------------------------------------------
   (C) Copyright 2009: the FALCON developers (see list in AUTHORS file)

   See LICENSE file for licensing details.
*/

#include "logging_mod.h"
#include <falcon/error.h>
#include <falcon/autowstring.h>

namespace Falcon {

LogChannelSyslog::LogChannelSyslog( const String& identity, uint32 facility, int level ):
   LogChannel( level ),
   m_identity( identity ),
   m_facility( facility )
{
   init();
}

LogChannelSyslog::LogChannelSyslog( const String& identity, const String &fmt, uint32 facility, int level ):
   LogChannel( fmt, level ),
   m_identity( identity ),
   m_facility( facility )

{
	init();
}


LogChannelSyslog::~LogChannelSyslog()
{
   CloseEventLog( (HANDLE) m_sysdata );
}

void LogChannelSyslog::init()
{
   AutoWString appname( m_identity );
   m_sysdata = (void*) OpenEventLogW( NULL, appname.w_str() );
   
   if ( m_sysdata == 0 )
   {
      throw new IoError( ErrorParam( FALCON_LOGGING_ERROR_OPEN, __LINE__ )
		  .origin( e_orig_runtime )
		  .sysError( GetLastError() ) );
   }
}


void LogChannelSyslog::writeLogEntry( const String& entry, LogChannel::LogMessage* pOrigMsg )
{
   WORD wType;
   DWORD dwEventID;

   if ( pOrigMsg->m_level <= LOGLEVEL_ERROR )
   {  
      wType = EVENTLOG_ERROR_TYPE;
	  dwEventID = 3 << 30;
   }
   else if ( pOrigMsg->m_level == LOGLEVEL_WARN )
   {
      wType = EVENTLOG_WARNING_TYPE;
	  dwEventID = 2 << 30;
   }
   else {
      wType = EVENTLOG_INFORMATION_TYPE;
	  dwEventID = 1 << 30;
   }

   // From MS docs; event ID  = gravity | custom | facility | code;
   dwEventID |= (1 << 29) | ((m_facility&0x1FF) << 16) | (pOrigMsg->m_code & 0xFFFF);

   AutoWString w_msg( entry );
   
   const wchar_t* strings[] = { w_msg.w_str() };
   ReportEventW(
	   (HANDLE)m_sysdata,	// __in  HANDLE hEventLog,
	   wType,				// __in  WORD wType,
	   m_facility,			// __in  WORD wCategory,
	   dwEventID,			// __in  DWORD dwEventID,
	   NULL,				// __in  PSID lpUserSid,
	   1,					// __in  WORD wNumStrings,
	   0,					// __in  DWORD dwDataSize,
	   strings,				// __in  LPCTSTR *lpStrings,
	   NULL					// __in  LPVOID lpRawData
	   );

}
	   
}

/* end of logging_mod_win.cpp */