MXS-2005: Move Logger into maxutils
Moved the logger into the maxutils library as it is a generic utility. Also moved mxs_strerror into it as it depends on it.
This commit is contained in:
29
maxutils/maxbase/include/maxbase/error.h
Normal file
29
maxutils/maxbase/include/maxbase/error.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2022-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <maxbase/cdefs.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
inline const char* mxb_strerror(int error)
|
||||||
|
{
|
||||||
|
// Enough for all errors
|
||||||
|
static thread_local char errbuf[512];
|
||||||
|
#ifdef HAVE_GLIBC
|
||||||
|
return strerror_r(error, errbuf, sizeof(errbuf));
|
||||||
|
#else
|
||||||
|
strerror_r(error, errbuf, sizeof(errbuf));
|
||||||
|
return errbuf;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@ -12,7 +12,7 @@
|
|||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <maxscale/ccdefs.hh>
|
#include <maxbase/ccdefs.hh>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace maxscale
|
namespace maxbase
|
||||||
{
|
{
|
||||||
|
|
||||||
// Minimal logger interface
|
// Minimal logger interface
|
||||||
@ -1,3 +1,3 @@
|
|||||||
add_library(maxbase STATIC eventcount.cc stopwatch.cc stacktrace.cc)
|
add_library(maxbase STATIC eventcount.cc stopwatch.cc stacktrace.cc logger.cc)
|
||||||
set_target_properties(maxbase PROPERTIES VERSION "1.0.0" LINK_FLAGS -Wl,-z,defs)
|
set_target_properties(maxbase PROPERTIES VERSION "1.0.0" LINK_FLAGS -Wl,-z,defs)
|
||||||
install(TARGETS maxbase DESTINATION lib)
|
install(TARGETS maxbase DESTINATION lib)
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "internal/logger.hh"
|
#include <maxbase/logger.hh>
|
||||||
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -22,7 +22,10 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include <maxscale/debug.h>
|
#include <maxbase/error.h>
|
||||||
|
|
||||||
|
// TODO: move <maxscale/debug.h> into maxbase
|
||||||
|
#define ss_dassert(a)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error logging for the logger itself.
|
* Error logging for the logger itself.
|
||||||
@ -44,7 +47,7 @@ int open_fd(const std::string& filename)
|
|||||||
|
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Failed to open file '%s': %d, %s\n", filename.c_str(), errno, mxs_strerror(errno));
|
LOG_ERROR("Failed to open file '%s': %d, %s\n", filename.c_str(), errno, mxb_strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
@ -68,7 +71,7 @@ bool should_log_error()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace maxscale
|
namespace maxbase
|
||||||
{
|
{
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -122,7 +125,7 @@ bool FileLogger::write(const char* msg, int len)
|
|||||||
{
|
{
|
||||||
if (should_log_error()) // Coarse error suppression
|
if (should_log_error()) // Coarse error suppression
|
||||||
{
|
{
|
||||||
LOG_ERROR("Failed to write to log: %d, %s\n", errno, mxs_strerror(errno));
|
LOG_ERROR("Failed to write to log: %d, %s\n", errno, mxb_strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
rval = false;
|
rval = false;
|
||||||
@ -194,7 +197,7 @@ bool FileLogger::write_header()
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Error: Writing log header failed due to %d, %s\n",
|
LOG_ERROR("Error: Writing log header failed due to %d, %s\n",
|
||||||
errno, mxs_strerror(errno));
|
errno, mxb_strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
@ -228,7 +231,7 @@ bool FileLogger::write_footer(const char* suffix)
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Error: Writing log footer failed due to %d, %s\n",
|
LOG_ERROR("Error: Writing log footer failed due to %d, %s\n",
|
||||||
errno, mxs_strerror(errno));
|
errno, mxb_strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
@ -22,7 +22,6 @@ add_library(maxscale-common SHARED
|
|||||||
listener.cc
|
listener.cc
|
||||||
load_utils.cc
|
load_utils.cc
|
||||||
log_manager.cc
|
log_manager.cc
|
||||||
logger.cc
|
|
||||||
mariadb.cc
|
mariadb.cc
|
||||||
maxscale_pcre2.cc
|
maxscale_pcre2.cc
|
||||||
misc.cc
|
misc.cc
|
||||||
|
|||||||
@ -21,17 +21,16 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <maxbase/error.h>
|
||||||
|
#include <maxbase/logger.hh>
|
||||||
|
|
||||||
#include <maxscale/config.h>
|
#include <maxscale/config.h>
|
||||||
#include <maxscale/debug.h>
|
#include <maxscale/debug.h>
|
||||||
#include <maxscale/json_api.h>
|
#include <maxscale/json_api.h>
|
||||||
#include <maxscale/session.h>
|
#include <maxscale/session.h>
|
||||||
#include <maxscale/utils.h>
|
#include <maxscale/utils.h>
|
||||||
|
|
||||||
#include "internal/logger.hh"
|
static std::unique_ptr<mxb::Logger> logger;
|
||||||
|
|
||||||
using namespace maxscale;
|
|
||||||
|
|
||||||
static std::unique_ptr<Logger> logger;
|
|
||||||
|
|
||||||
const std::string LOGFILE_NAME = "maxscale.log";
|
const std::string LOGFILE_NAME = "maxscale.log";
|
||||||
|
|
||||||
@ -329,11 +328,11 @@ bool mxs_log_init(const char* ident, const char* logdir, mxs_log_target_t target
|
|||||||
{
|
{
|
||||||
case MXS_LOG_TARGET_FS:
|
case MXS_LOG_TARGET_FS:
|
||||||
case MXS_LOG_TARGET_DEFAULT:
|
case MXS_LOG_TARGET_DEFAULT:
|
||||||
logger = FileLogger::create(filename);
|
logger = mxb::FileLogger::create(filename);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MXS_LOG_TARGET_STDOUT:
|
case MXS_LOG_TARGET_STDOUT:
|
||||||
logger = StdoutLogger::create(filename);
|
logger = mxb::StdoutLogger::create(filename);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -864,13 +863,7 @@ int mxs_log_message(int priority,
|
|||||||
|
|
||||||
const char* mxs_strerror(int error)
|
const char* mxs_strerror(int error)
|
||||||
{
|
{
|
||||||
static thread_local char errbuf[MXS_STRERROR_BUFLEN];
|
return mxb_strerror(error);
|
||||||
#ifdef HAVE_GLIBC
|
|
||||||
return strerror_r(error, errbuf, sizeof(errbuf));
|
|
||||||
#else
|
|
||||||
strerror_r(error, errbuf, sizeof(errbuf));
|
|
||||||
return errbuf;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* get_log_priorities()
|
json_t* get_log_priorities()
|
||||||
|
|||||||
Reference in New Issue
Block a user