Skip to content

Commit

Permalink
[xlog] add filter for user to control other module’s log
Browse files Browse the repository at this point in the history
  • Loading branch information
garryyan committed Dec 24, 2019
1 parent c791ee9 commit b034438
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions mars/comm/verinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#ifndef Mars_verinfo_h
#define Mars_verinfo_h

#define MARS_REVISION "b59f9feb"
#define MARS_REVISION "c791ee96"
#define MARS_PATH "rb/2019-DEC"
#define MARS_URL ""
#define MARS_BUILD_TIME "2019-12-18 16:23:26"
#define MARS_BUILD_TIME "2019-12-24 15:28:09"
#define MARS_TAG ""

#endif
27 changes: 15 additions & 12 deletions mars/comm/xlogger/xlogger.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://opensource.org/licenses/MIT

// Unless required by applicable law or agreed to in writing, software distributed under the License is
// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions and
// limitations under the License.

// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://opensource.org/licenses/MIT

// Unless required by applicable law or agreed to in writing, software distributed under the License is
// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions and
// limitations under the License.

/*
============================================================================
Name : xlogger.h
Expand Down Expand Up @@ -146,6 +146,9 @@ class XLogger {

gettimeofday(&m_info.timeval, NULL);
if (m_hook && !m_hook(m_info, m_message)) return;

xlogger_filter_t filter = xlogger_GetFilter();
if (filter && filter(&m_info, m_message.c_str()) <= 0) return;

if (m_isassert)
xlogger_Assert(m_isinfonull?NULL:&m_info, m_exp, m_message.c_str());
Expand Down
9 changes: 9 additions & 0 deletions mars/comm/xlogger/xloggerbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ xlogger_appender_t xlogger_SetAppender(xlogger_appender_t _appender) {
return __xlogger_SetAppender_impl(_appender);
}

static xlogger_filter_t sg_filter = NULL;
void xlogger_SetFilter(xlogger_filter_t _filter) {
sg_filter = _filter;
}

xlogger_filter_t xlogger_GetFilter() {
return sg_filter;
}

void xlogger_Write(const XLoggerInfo* _info, const char* _log) {
if (NULL != &__xlogger_Write_impl)
__xlogger_Write_impl(_info, _log);
Expand Down
4 changes: 4 additions & 0 deletions mars/comm/xlogger/xloggerbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ void xlogger_SetLevel(TLogLevel _level);
int xlogger_IsEnabledFor(TLogLevel _level);
xlogger_appender_t xlogger_SetAppender(xlogger_appender_t _appender);

typedef int (*xlogger_filter_t)(XLoggerInfo* _info, const char* _log);
void xlogger_SetFilter(xlogger_filter_t _filter);
xlogger_filter_t xlogger_GetFilter();

// no level filter
#ifdef __GNUC__
__attribute__((__format__(printf, 3, 4)))
Expand Down

0 comments on commit b034438

Please sign in to comment.