Files
MaxScale/log_manager/log_manager.h
Johan Wikman a8535f42af Remove all traces of logfile_t
The earlier log file based approach for enabling and disabling
messages has now been completely replaced with the syslog priority
based approach.

Similarly as with log files before it is now possible to enable
and disable a log priority for a particular session, even though
it apparently has not been used much.

The local test-programs of the logging has got minimal attention
only to make them compile. They should get an overhaul as they did
not work before either.
2015-11-23 19:10:53 +02:00

133 lines
4.2 KiB
C

/*
* This file is distributed as part of the MariaDB Corporation MaxScale. It is free
* software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright MariaDB Corporation Ab 2013-2014
*/
#if !defined(LOG_MANAGER_H)
#define LOG_MANAGER_H
#include <syslog.h>
#if defined(__cplusplus)
extern "C" {
#endif
/*
* We need a common.h file that is included by every component.
*/
#if !defined(STRERROR_BUFLEN)
#define STRERROR_BUFLEN 512
#endif
enum mxs_log_priorities
{
MXS_LOG_EMERG = (1 << LOG_EMERG),
MXS_LOG_ALERT = (1 << LOG_ALERT),
MXS_LOG_CRIT = (1 << LOG_CRIT),
MXS_LOG_ERR = (1 << LOG_ERR),
MXS_LOG_WARNING = (1 << LOG_WARNING),
MXS_LOG_NOTICE = (1 << LOG_NOTICE),
MXS_LOG_INFO = (1 << LOG_INFO),
MXS_LOG_DEBUG = (1 << LOG_DEBUG),
MXS_LOG_MASK = (MXS_LOG_EMERG | MXS_LOG_ALERT | MXS_LOG_CRIT | MXS_LOG_ERR |
MXS_LOG_WARNING | MXS_LOG_NOTICE | MXS_LOG_INFO | MXS_LOG_DEBUG),
};
typedef enum
{
LOG_TARGET_DEFAULT = 0,
LOG_TARGET_FS = 1, // File system
LOG_TARGET_SHMEM = 2, // Shared memory
} log_target_t;
/**
* Thread-specific logging information.
*/
typedef struct log_info
{
size_t li_sesid;
int li_enabled_priorities;
} log_info_t;
extern int lm_enabled_priorities_bitmask;
extern ssize_t log_ses_count[];
extern __thread log_info_t tls_log_info;
/**
* Check if specified log type is enabled in general or if it is enabled
* for the current session.
*/
#define MXS_LOG_PRIORITY_IS_ENABLED(priority) \
(((lm_enabled_priorities_bitmask & (1 << priority)) || \
(log_ses_count[priority] > 0 && \
tls_log_info.li_enabled_priorities & (1 << priority))) ? true : false)
/**
* LOG_AUGMENT_WITH_FUNCTION Each logged line is suffixed with [function-name].
*/
typedef enum
{
LOG_AUGMENT_WITH_FUNCTION = 1,
LOG_AUGMENTATION_MASK = (LOG_AUGMENT_WITH_FUNCTION)
} log_augmentation_t;
bool mxs_log_init(const char* ident, const char* logdir, log_target_t target);
void mxs_log_finish(void);
int mxs_log_flush();
int mxs_log_flush_sync();
int mxs_log_rotate();
int mxs_log_set_priority_enabled(int priority, bool enabled);
void mxs_log_set_syslog_enabled(bool enabled);
void mxs_log_set_maxscalelog_enabled(bool enabled);
void mxs_log_set_highprecision_enabled(bool enabled);
void mxs_log_set_augmentation(int bits);
int mxs_log_message(int priority,
const char* file, int line, const char* function,
const char* format, ...) __attribute__((format(printf, 5, 6)));
/**
* Log an error, warning, notice, info, or debug message.
*
* @param priority One of the syslog constants (LOG_ERR, LOG_WARNING, ...)
* @param format The printf format of the message.
* @param ... Arguments, depending on the format.
*
* NOTE: Should typically not be called directly. Use some of the
* MXS_ERROR, MXS_WARNING, etc. macros instead.
*/
#define MXS_LOG_MESSAGE(priority, format, ...)\
mxs_log_message(priority, __FILE__, __LINE__, __func__, format, ##__VA_ARGS__)
/**
* Log an error, warning, notice, info, or debug message.
*
* @param format The printf format of the message.
* @param ... Arguments, depending on the format.
*/
#define MXS_ERROR(format, ...) MXS_LOG_MESSAGE(LOG_ERR, format, ##__VA_ARGS__)
#define MXS_WARNING(format, ...) MXS_LOG_MESSAGE(LOG_WARNING, format, ##__VA_ARGS__)
#define MXS_NOTICE(format, ...) MXS_LOG_MESSAGE(LOG_NOTICE, format, ##__VA_ARGS__)
#define MXS_INFO(format, ...) MXS_LOG_MESSAGE(LOG_INFO, format, ##__VA_ARGS__)
#define MXS_DEBUG(format, ...) MXS_LOG_MESSAGE(LOG_DEBUG, format, ##__VA_ARGS__)
#if defined(__cplusplus)
}
#endif
#endif /** LOG_MANAGER_H */