-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83136a7
commit 91e4e04
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if(UNIX) | ||
add_executable(Syslog Main.cpp) | ||
target_link_libraries(Syslog plog) | ||
target_compile_options(Syslog PRIVATE -pthread) | ||
target_link_options(Syslog PRIVATE -pthread) | ||
set_target_properties(Syslog PROPERTIES FOLDER Samples) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Syslog - shows how to use the syslog appender/formatter. | ||
// For the mappings between plog and syslog severities, refer to SyslogAppender | ||
// | ||
|
||
#include <plog/Log.h> | ||
#include <plog/Init.h> | ||
#include <plog/Formatters/SyslogFormatter.h> | ||
#include <plog/Appenders/SyslogAppender.h> | ||
#if __cplusplus >= 201103L | ||
#include <thread> | ||
#endif | ||
|
||
static void log_messages() | ||
{ | ||
PLOG_VERBOSE << "This is a VERBOSE message"; | ||
PLOG_DEBUG << "This is a DEBUG message"; | ||
PLOG_INFO << "This is an INFO message"; | ||
PLOG_WARNING << "This is a WARNING message"; | ||
PLOG_ERROR << "This is an ERROR message"; | ||
PLOG_FATAL << "This is a FATAL message"; | ||
} | ||
|
||
int main() | ||
{ | ||
static plog::SyslogAppender<plog::SyslogFormatter> syslogAppender; | ||
plog::init(plog::verbose, &syslogAppender); | ||
|
||
// Calling openlog() is optional. If omitted, the application name is | ||
// used (depends on the used C library) and the PID is not included. | ||
openlog("MyApp", LOG_PID, LOG_USER); | ||
|
||
// optional: log only messages up to PLOG_INFO (maps to LOG_NOTICE) | ||
setlogmask(LOG_UPTO(LOG_NOTICE)); | ||
|
||
#if __cplusplus >= 201103L | ||
// optional: start a 2nd thread which also generates log messages | ||
// you'll get the same PID but different TID values in the syslog file | ||
std::thread myThread(log_messages); | ||
#endif | ||
|
||
log_messages(); | ||
|
||
#if __cplusplus >= 201103L | ||
// wait until the 2nd thread has finished | ||
myThread.join(); | ||
#endif | ||
|
||
// Calling closelog() is optional | ||
closelog(); | ||
|
||
return 0; | ||
} |