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:
Markus Mäkelä 2018-08-13 15:50:05 +03:00
parent dc2578ed98
commit c543525c1b
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
6 changed files with 49 additions and 25 deletions

View 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
}

View File

@ -12,7 +12,7 @@
* Public License.
*/
#include <maxscale/ccdefs.hh>
#include <maxbase/ccdefs.hh>
#include <string>
#include <mutex>
@ -20,7 +20,7 @@
#include <unistd.h>
namespace maxscale
namespace maxbase
{
// Minimal logger interface

View File

@ -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)
install(TARGETS maxbase DESTINATION lib)

View File

@ -11,7 +11,7 @@
* Public License.
*/
#include "internal/logger.hh"
#include <maxbase/logger.hh>
#include <syslog.h>
#include <fcntl.h>
@ -22,7 +22,10 @@
#include <cstdio>
#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.
@ -44,7 +47,7 @@ int open_fd(const std::string& filename)
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;
@ -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
{
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;
@ -194,7 +197,7 @@ bool FileLogger::write_header()
if (!ok)
{
LOG_ERROR("Error: Writing log header failed due to %d, %s\n",
errno, mxs_strerror(errno));
errno, mxb_strerror(errno));
}
return ok;
@ -228,7 +231,7 @@ bool FileLogger::write_footer(const char* suffix)
if (!ok)
{
LOG_ERROR("Error: Writing log footer failed due to %d, %s\n",
errno, mxs_strerror(errno));
errno, mxb_strerror(errno));
}
return ok;

View File

@ -22,7 +22,6 @@ add_library(maxscale-common SHARED
listener.cc
load_utils.cc
log_manager.cc
logger.cc
mariadb.cc
maxscale_pcre2.cc
misc.cc

View File

@ -21,17 +21,16 @@
#include <string>
#include <mutex>
#include <maxbase/error.h>
#include <maxbase/logger.hh>
#include <maxscale/config.h>
#include <maxscale/debug.h>
#include <maxscale/json_api.h>
#include <maxscale/session.h>
#include <maxscale/utils.h>
#include "internal/logger.hh"
using namespace maxscale;
static std::unique_ptr<Logger> logger;
static std::unique_ptr<mxb::Logger> logger;
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_DEFAULT:
logger = FileLogger::create(filename);
logger = mxb::FileLogger::create(filename);
break;
case MXS_LOG_TARGET_STDOUT:
logger = StdoutLogger::create(filename);
logger = mxb::StdoutLogger::create(filename);
break;
default:
@ -864,13 +863,7 @@ int mxs_log_message(int priority,
const char* mxs_strerror(int error)
{
static thread_local char errbuf[MXS_STRERROR_BUFLEN];
#ifdef HAVE_GLIBC
return strerror_r(error, errbuf, sizeof(errbuf));
#else
strerror_r(error, errbuf, sizeof(errbuf));
return errbuf;
#endif
return mxb_strerror(error);
}
json_t* get_log_priorities()