Add syslog support.

This commit is contained in:
XMRig 2017-06-25 02:04:59 +03:00
parent e97cd98f90
commit faf793b0aa
5 changed files with 36 additions and 8 deletions

View File

@ -4,6 +4,10 @@ project(xmrig)
option(WITH_LIBCPUID "Use Libcpuid" ON)
option(WITH_AEON "CryptoNight-Lite support" ON)
include (CheckIncludeFile)
set(HEADERS
src/3rdparty/align.h
src/App.h
@ -166,6 +170,12 @@ else()
set(SOURCES_CPUID src/Cpu_stub.cpp)
endif()
CHECK_INCLUDE_FILE (syslog.h HAVE_SYSLOG_H)
if (HAVE_SYSLOG_H)
add_definitions(/DHAVE_SYSLOG_H)
set(SOURCES_SYSLOG src/log/SysLog.h src/log/SysLog.cpp)
endif()
include_directories(src)
include_directories(src/3rdparty)
include_directories(src/3rdparty/jansson)
@ -173,5 +183,5 @@ include_directories(${UV_INCLUDE_DIR})
add_subdirectory(src/3rdparty/jansson)
add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO})
add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG})
target_link_libraries(xmrig jansson ${UV_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB})

View File

@ -40,6 +40,11 @@
#include "workers/Workers.h"
#ifdef HAVE_SYSLOG_H
# include "log/SysLog.h"
#endif
App *App::m_self = nullptr;
@ -63,6 +68,12 @@ App::App(int argc, char **argv) :
Log::add(new FileLog(m_options->logFile()));
}
# ifdef HAVE_SYSLOG_H
if (m_options->syslog()) {
Log::add(new SysLog());
}
# endif
m_network = new Network(m_options);
uv_signal_init(uv_default_loop(), &m_signal);

View File

@ -22,19 +22,26 @@
*/
#include <syslog.h>
#include "log/SysLog.h"
#include "version.h"
SysLog::SysLog()
{
openlog(APP_ID, LOG_PID, LOG_USER);
}
void SysLog::message(int level, const char* fmt, va_list args)
void SysLog::message(int level, const char *fmt, va_list args)
{
vsyslog(level, fmt, args);
}
void SysLog::text(const char* fmt, va_list args)
void SysLog::text(const char *fmt, va_list args)
{
message(LOG_INFO, fmt, args);
}

View File

@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SYSLOG_BACKEND_H__
#define __SYSLOG_BACKEND_H__
#ifndef __SYSLOG_H__
#define __SYSLOG_H__
#include "interfaces/ILogBackend.h"
@ -33,8 +33,8 @@ class SysLog : public ILogBackend
public:
SysLog();
void message(int level, const char* fmt, va_list args) override;
void text(const char* fmt, va_list args) override;
void message(int level, const char *fmt, va_list args) override;
void text(const char *fmt, va_list args) override;
};
#endif /* __SYSLOG_BACKEND_H__ */

View File

@ -152,7 +152,7 @@ void Hashrate::print()
char num3[8];
char num4[8];
LOG_INFO(Options::i()->colors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m max: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s highest: %s H/s",
LOG_INFO(Options::i()->colors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m max: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s max: %s H/s",
format(calc(2500), num1, sizeof(num1)),
format(calc(60000), num2, sizeof(num2)),
format(calc(900000), num3, sizeof(num3)),