33 namespace LogOutputWindowsImp
35 bool oldWindows() noexcept
37 return !IsWindowsVistaOrGreater() ;
42void G::LogOutput::osoutput(
int fd , Severity severity ,
char * message , std::size_t n )
46 if( m_config.m_use_syslog &&
47 severity != Severity::Debug &&
48 severity != Severity::InfoVerbose &&
51 DWORD
id = 0x400003E9L ;
52 WORD type = EVENTLOG_INFORMATION_TYPE ;
53 if( severity == Severity::Warning )
56 type = EVENTLOG_WARNING_TYPE ;
58 else if( severity == Severity::Error || severity == Severity::Assertion )
61 type = EVENTLOG_ERROR_TYPE ;
66 if( LogOutputWindowsImp::oldWindows() )
70 nowide::reportEvent( m_handle ,
id , type , message ) ;
76 if(
fd > 2 ) message[n++] =
'\r' ;
81void G::LogOutput::osinit()
83 if( m_config.m_use_syslog )
86 if( !this_exe.empty() )
90 std::string this_name = this_exe.withoutExtension().basename() ;
91 m_handle = nowide::registerEventSource( this_name ) ;
92 if( m_handle == HNULL && !m_config.m_allow_bad_syslog )
93 throw EventLogError() ;
103 std::string reg_path = std::string(
"SYSTEM/CurrentControlSet/services/eventlog/Application/")
104 .append( exe_path.withoutExtension().basename() ) ;
107 LONG e = nowide::regCreateKey( reg_path , &key ) ;
108 if( e == ERROR_SUCCESS && key != 0 )
110 DWORD types = EVENTLOG_INFORMATION_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_ERROR_TYPE ;
111 nowide::regSetValue( key ,
"EventMessageFile" , exe_path.str() ) ;
112 nowide::regSetValue( key ,
"CategoryCount" , DWORD(1) ) ;
113 nowide::regSetValue( key ,
"CategoryMessageFile" , exe_path.str() ) ;
114 nowide::regSetValue( key ,
"TypesSupported" , types ) ;
120void G::LogOutput::oscleanup() const noexcept
122 if( m_handle != HNULL )
123 DeregisterEventSource( m_handle ) ;
static ssize_t write(int fd, const char *, std::size_t) noexcept
Calls ::write() or equivalent.
static void register_(const Path &exe)
Registers the given executable as a source of logging.
int fd() const noexcept
Returns the output file descriptor.
static Path exe()
Returns the absolute path of the current executable, independent of the argv array passed to main().
Contains inline functions that convert to and from UTF-8 strings in order to call wide-character "W()...