Commit aef79d63 authored by Raphael Defosseux's avatar Raphael Defosseux

feat(amf): logging level can be setup at run-time and not build-time

parent c239d9c8
[submodule "src/common-src"]
path = src/common-src
url = https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-common-src.git
[submodule "build/common-build"]
path = build/common-build
url = https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-common-build.git
[submodule "ci-scripts/common-ci"]
path = ci-scripts/common-ci
url = https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-common-ci.git
......@@ -10,4 +10,10 @@ set (OPENAIRCN_DIR $ENV{OPENAIRCN_DIR})
set (BUILD_TOP_DIR ${OPENAIRCN_DIR}/build)
set (SRC_TOP_DIR $ENV{OPENAIRCN_DIR}/src)
################################################
# For common-src usage
################################################
set ( NF_TARGET amf )
set ( MOUNTED_COMMON common-src)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../src/oai-amf/CMakeLists.txt)
common-build @ 64c33452
Subproject commit 64c334526218fdb80020bd08a387d7bd092ddcda
......@@ -62,16 +62,67 @@ install_spdlog_from_git() {
fi
git clone $GIT_URL
cd spdlog && git checkout master
cd spdlog && git checkout v1.11.0
mkdir _build && cd _build
$CMAKE -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DSPDLOG_FMT_EXTERNAL=ON -DSPDLOG_BUILD_SHARED=ON ..
make
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
$SUDO make install
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
# enable syslog, Useless (defined in SMF code)
sed -i '/#define SPDLOG_ENABLE_SYSLOG/s/^\/\///g' include/spdlog/tweakme.h
popd
rm -Rf $OPENAIRCN_DIR/build/ext/spdlog/_build
fi
echo "spdlog installation complete"
return 0
}
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_fmt_from_git() {
echo "Starting to install fmt"
if [ $1 -eq 0 ]; then
read -p "Do you want to install fmt? <y/N> " prompt
OPTION=""
else
prompt='y'
OPTION="-y"
fi
if [ $2 -eq 0 ]; then
debug=0
else
debug=1
fi
if [[ $prompt =~ [yY](es)* ]]
then
GIT_URL=https://github.com/fmtlib/fmt/
echo "Install fmt from $GIT_URL"
pushd $OPENAIRCN_DIR/build/ext
echo "Downloading fmt"
if [[ $OPTION =~ -[yY](es)* ]]
then
$SUDO rm -rf fmt
fi
git clone $GIT_URL
cd fmt && git checkout 9.0.0
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
mkdir _build && cd _build
$CMAKE -G "Unix Makefiles" -DFMT_TEST=OFF -DBUILD_SHARED_LIBS=TRUE ..
make
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
$SUDO make install
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
popd
rm -Rf $OPENAIRCN_DIR/build/ext/fmt/_build
fi
echo "fmt installation complete"
return 0
}
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
......@@ -404,6 +455,9 @@ check_install_amf_deps(){
ret=$?;[[ $ret -ne 0 ]] && return $ret
echo "distro libs installation complete"
install_fmt_from_git $1 $2
ret=$?;[[ $ret -ne 0 ]] && return $ret
install_spdlog_from_git $1 $2
ret=$?;[[ $ret -ne 0 ]] && return $ret
......
......@@ -399,21 +399,23 @@ pipeline {
// Temporary Images from Merge-Request Runs are kept in local private registry
stage ('Pushing Image to Official Registry') {
steps {
script {
// Only in case of push to target branch!
if ("PUSH".equals(env.gitlabActionType)) {
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.DockerHubCredentials}", usernameVariable: 'DH_Username', passwordVariable: 'DH_Password']
]) {
sh "echo ${DH_Password} | docker login --username ${DH_Username} --password-stdin"
lock(ubuntuBuildResource) {
script {
// Only in case of push to target branch!
if ("PUSH".equals(env.gitlabActionType)) {
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.DockerHubCredentials}", usernameVariable: 'DH_Username', passwordVariable: 'DH_Password']
]) {
sh "echo ${DH_Password} | docker login --username ${DH_Username} --password-stdin"
}
sh "docker login -u oaicicd -p oaicicd ${PrivateRegistryURL}"
sh "docker pull ${PrivateRegistryURL}/oai-amf:${amf_tag}"
sh "docker image tag ${PrivateRegistryURL}/oai-amf:${amf_tag} ${DH_Account}/oai-amf:develop"
sh "docker push ${DH_Account}/oai-amf:develop"
sh "docker rmi ${DH_Account}/oai-amf:develop ${PrivateRegistryURL}/oai-amf:${amf_tag}"
sh "docker logout ${PrivateRegistryURL}"
sh "docker logout"
}
sh "docker login -u oaicicd -p oaicicd ${PrivateRegistryURL}"
sh "docker pull ${PrivateRegistryURL}/oai-amf:${amf_tag}"
sh "docker image tag ${PrivateRegistryURL}/oai-amf:${amf_tag} ${DH_Account}/oai-amf:develop"
sh "docker push ${DH_Account}/oai-amf:develop"
sh "docker rmi ${DH_Account}/oai-amf:develop ${PrivateRegistryURL}/oai-amf:${amf_tag}"
sh "docker logout ${PrivateRegistryURL}"
sh "docker logout"
}
}
}
......
common-ci @ c458e9dd
Subproject commit c458e9dd6a5cbce1306680d4289012b8f493ff85
......@@ -129,6 +129,8 @@ COPY --from=oai-amf-builder \
/usr/local/lib64/libpistache.so.0 \
/usr/local/lib/libnghttp2_asio.so \
/usr/local/lib/libnghttp2_asio.so.1 \
/usr/local/lib64/libspdlog.so \
/usr/local/lib64/libfmt.so \
/usr/lib64/
RUN ldconfig && \
......
......@@ -55,8 +55,7 @@ COPY ./build/cmake_modules /openair-amf/cmake_modules
# Installing all the needed libraries/packages to build and run AMF
WORKDIR /openair-amf/build/scripts
RUN ./build_amf --install-deps --force && \
cp -Rf /openair-amf/build/ext /openair-amf-ext-ref
RUN ./build_amf --install-deps --force
#---------------------------------------------------------------------
# BUILDER IMAGE
......@@ -131,6 +130,7 @@ COPY --from=oai-amf-builder \
/usr/local/lib/libnghttp2.so.14 \
/usr/local/lib/libnghttp2_asio.so.1 \
/usr/local/lib/libpistache.so \
/usr/local/lib/libfmt.so \
# Ubuntu 18 --> boost 67 will be copied
/usr/lib/libboost_system.so.1.* \
/usr/lib/libboost_thread.so.1.* \
......
......@@ -27,6 +27,7 @@ AMF =
PID_DIRECTORY = "{{ env["PID_DIRECTORY"] if "PID_DIRECTORY" in env.keys() else '/var/run' }}"; # /var/run is the default
AMF_NAME = "OAI-AMF";
LOG_LEVEL = "{{ env["LOG_LEVEL"] if "LOG_LEVEL" in env.keys() else 'debug' }}";
RELATIVE_CAPACITY = 30;
# Display statistics about whole system (in seconds)
......@@ -147,4 +148,4 @@ AMF =
ORDERED_SUPPORTED_INTEGRITY_ALGORITHM_LIST = {{ env["INT_ALGO_LIST"] if "INT_ALGO_LIST" in env.keys() else [ "NIA0" , "NIA1" , "NIA2" ] | tojson }} ;
ORDERED_SUPPORTED_CIPHERING_ALGORITHM_LIST = {{ env["CIPH_ALGO_LIST"] if "CIPH_ALGO_LIST" in env.keys() else [ "NEA0" , "NEA1" , "NEA2" ] | tojson }} ;
};
};
\ No newline at end of file
};
......@@ -19,7 +19,6 @@
# contact@openairinterface.org
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/amf-app)
include_directories(${SRC_TOP_DIR}/itti)
include_directories(${SRC_TOP_DIR}/itti/msgs)
......@@ -43,6 +42,7 @@ include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka)
include_directories(${SRC_TOP_DIR}/secu_algorithms/nas_enc_int)
include_directories(${SRC_TOP_DIR}/utils)
include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
file(GLOB AMF_src_files
${CMAKE_CURRENT_SOURCE_DIR}/amf_app.cpp
......@@ -66,9 +66,9 @@ file(GLOB AMF_src_files
${SRC_TOP_DIR}/ngap/libngap/*.c
${SRC_TOP_DIR}/ngap/ngap_app/*.cpp
${SRC_TOP_DIR}/ngap/ngapMsgs/*.cpp
${SRC_TOP_DIR}/ngap/ngapIEs/*.cpp
${SRC_TOP_DIR}/ngap/ngapIEs/*.cpp
)
add_library (AMF STATIC
${AMF_src_files}
)
......
......@@ -66,6 +66,7 @@ amf_config::amf_config() {
nssf_addr.port = DEFAULT_HTTP1_PORT;
nssf_addr.api_version = DEFAULT_SBI_API_VERSION;
instance = 0;
log_level = spdlog::level::debug;
n2 = {};
sbi = {};
sbi_api_version = DEFAULT_SBI_API_VERSION;
......@@ -159,6 +160,16 @@ int amf_config::load(const std::string& config_file) {
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// Log Level
try {
std::string string_level;
amf_cfg.lookupValue(AMF_CONFIG_STRING_LOG_LEVEL, string_level);
log_level = spdlog::level::from_str(string_level);
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// GUAMI
try {
const Setting& guami_cfg = amf_cfg[AMF_CONFIG_STRING_GUAMI];
......@@ -848,6 +859,9 @@ void amf_config::display() {
Logger::config().info(
" Use HTTP2..............: %s",
support_features.use_http2 ? "Yes" : "No");
Logger::config().info(
"- Log Level will be .......: %s",
spdlog::level::to_string_view(log_level));
}
//------------------------------------------------------------------------------
......@@ -1018,6 +1032,7 @@ std::string amf_config::get_smf_pdu_session_base_uri(
void amf_config::to_json(nlohmann::json& json_data) const {
json_data["instance"] = instance;
json_data["pid_dir"] = pid_dir;
json_data["log_level"] = log_level;
json_data["amf_name"] = amf_name;
json_data["guami"] = guami.to_json();
json_data["guami_list"] = nlohmann::json::array();
......@@ -1076,6 +1091,9 @@ bool amf_config::from_json(nlohmann::json& json_data) {
if (json_data.find("amf_name") != json_data.end()) {
amf_name = json_data["amf_name"].get<std::string>();
}
if (json_data.find("log_level") != json_data.end()) {
log_level = json_data["log_level"].get<spdlog::level::level_enum>();
}
if (json_data.find("guami") != json_data.end()) {
guami.from_json(json_data["guami"]);
}
......
......@@ -113,6 +113,7 @@
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_USE_HTTP2 "USE_HTTP2"
#define AMF_CONFIG_STRING_FQDN_DNS "FQDN"
#define AMF_CONFIG_STRING_LOG_LEVEL "LOG_LEVEL"
using namespace libconfig;
......@@ -499,6 +500,7 @@ class amf_config {
unsigned int instance;
std::string pid_dir;
spdlog::level::level_enum log_level;
interface_cfg_t n2;
interface_cfg_t sbi;
itti_cfg_t itti;
......
......@@ -1146,7 +1146,8 @@ void amf_n1::registration_request_handle(
set_supi_2_nas_context(supi, nc);
Logger::amf_n1().info(
"Associating SUPI (%s) with nas_context (%p)", supi.c_str(), nc);
"Associating SUPI (%s) with nas_context (%p)", supi.c_str(),
(void*) nc.get());
if (!nc->is_stacs_available) {
ue_info_t ueItem;
ueItem.connStatus = "5GMM-CONNECTED"; //"CM-CONNECTED";
......@@ -1210,7 +1211,7 @@ void amf_n1::registration_request_handle(
"(" AMF_UE_NGAP_ID_FMT
") "
"for nas_signalling_establishment_request",
nc, amf_ue_ngap_id);
(void*) nc.get(), amf_ue_ngap_id);
set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc);
nc->ctx_avaliability_ind = false;
// change UE connection status CM-IDLE -> CM-CONNECTED
......@@ -2216,8 +2217,8 @@ void amf_n1::authentication_response_handle(
}
Logger::amf_n1().info(
"Found nas_context (%p) with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")", nc,
amf_ue_ngap_id);
"Found nas_context (%p) with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
(void*) nc.get(), amf_ue_ngap_id);
// Stop timer? common procedure finished!
nc->is_common_procedure_for_authentication_running = false;
// MM state: COMMON-PROCEDURE-INITIATED -> DEREGISTRED
......
......@@ -1079,9 +1079,8 @@ void amf_sbi::curl_http_client(
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.sbi.if_name.c_str());
if (http_version == 2) {
#if DEBUG_IS_ON
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
if (Logger::should_log(spdlog::level::debug))
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
......@@ -1368,9 +1367,8 @@ void amf_sbi::curl_http_client(
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.sbi.if_name.c_str());
if (http_version == 2) {
#if DEBUG_IS_ON
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
if (Logger::should_log(spdlog::level::debug))
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
......@@ -1513,9 +1511,8 @@ void amf_sbi::curl_http_client(
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.sbi.if_name.c_str());
if (http_version == 2) {
#if DEBUG_IS_ON
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
if (Logger::should_log(spdlog::level::debug))
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
......
common-src @ 12e0a397
Subproject commit 12e0a3977f4ae1672543075e523f0ec9b0a75bf4
......@@ -23,12 +23,12 @@ include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/utils/)
include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/ngap/libngap)
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/common/unicode)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
file(GLOB COMMON_SRC ${SRC_TOP_DIR}/common/conversions.cpp)
add_library(3GPP_COMMON_TYPES STATIC
${SRC_TOP_DIR}/common/logger.cpp
${SRC_TOP_DIR}/common/conversions.cpp
${SRC_TOP_DIR}/common/output_wrapper.cpp
)
......@@ -200,7 +200,7 @@ unsigned char* conv::format_string_as_hex(std::string str) {
memset(data, 0, str_len + 1);
memcpy((void*) data, (void*) str.c_str(), str_len);
Logger::amf_app().debug("Data %s (%d bytes)", data, str_len);
Logger::amf_app().debug("Data %s (%d bytes)", (void*) data, str_len);
Logger::amf_app().debug("Data (formatted):");
for (int i = 0; i < str_len; i++) {
char datatmp[3] = {0};
......@@ -215,18 +215,15 @@ unsigned char* conv::format_string_as_hex(std::string str) {
// Convert two hexadecimal characters into one character
unsigned int nAsciiCharacter;
sscanf(datatmp, "%x", &nAsciiCharacter);
#if DEBUG_IS_ON
printf("%x ", nAsciiCharacter);
#endif
if (Logger::should_log(spdlog::level::debug))
printf("%x ", nAsciiCharacter);
// Concatenate this character onto the output
datavalue[i / 2] = (unsigned char) nAsciiCharacter;
// Skip the next character
i++;
}
#if DEBUG_IS_ON
printf("\n");
#endif
if (Logger::should_log(spdlog::level::debug)) printf("\n");
free_wrapper((void**) &data);
return datavalue;
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* 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.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "logger.hpp"
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include "spdlog/sinks/syslog_sink.h"
Logger* Logger::m_singleton = NULL;
//------------------------------------------------------------------------------
void Logger::_init(
const char* app, const bool log_stdout, const bool log_rot_file) {
int num_sinks = 0;
spdlog::set_async_mode(2048);
#if TRACE_IS_ON
spdlog::level::level_enum llevel = spdlog::level::trace;
#elif DEBUG_IS_ON
spdlog::level::level_enum llevel = spdlog::level::debug;
#elif INFO_IS_ON
spdlog::level::level_enum llevel = spdlog::level::info;
#else
spdlog::level::level_enum llevel = spdlog::level::off;
#endif
// TODO: Log leve: "start", "warn ", "error"
if (log_stdout) {
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back(
std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>());
m_sinks[num_sinks++].get()->set_level(llevel);
}
if (log_rot_file) {
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
filename, 5 * 1024 * 1024, 3));
}
std::stringstream ss;
ss << "[%Y-%m-%dT%H:%M:%S.%f] [" << app << "] [%n] [%l] %v";
m_async_cmd = new _Logger("asnyc_c", m_sinks, ss.str().c_str());
m_amf_app = new _Logger("amf_app", m_sinks, ss.str().c_str());
m_config = new _Logger("config ", m_sinks, ss.str().c_str());
m_system = new _Logger("system ", m_sinks, ss.str().c_str());
m_sctp = new _Logger("sctp ", m_sinks, ss.str().c_str());
m_nas_mm = new _Logger("nas_mm ", m_sinks, ss.str().c_str());
m_ngap = new _Logger("ngap ", m_sinks, ss.str().c_str());
m_itti = new _Logger("itti ", m_sinks, ss.str().c_str());
m_amf_n2 = new _Logger("amf_n2 ", m_sinks, ss.str().c_str());
m_amf_n1 = new _Logger("amf_n1 ", m_sinks, ss.str().c_str());
m_amf_sbi = new _Logger("amf_sbi", m_sinks, ss.str().c_str());
m_amf_server = new _Logger("amf_server", m_sinks, ss.str().c_str());
}
//------------------------------------------------------------------------------
_Logger::_Logger(
const char* category, std::vector<spdlog::sink_ptr>& sinks,
const char* pattern)
: m_log(category, sinks.begin(), sinks.end()) {
m_log.set_pattern(pattern);
#if TRACE_IS_ON
m_log.set_level(spdlog::level::trace);
#elif DEBUG_IS_ON
m_log.set_level(spdlog::level::debug);
#elif INFO_IS_ON
m_log.set_level(spdlog::level::info);
#else
m_log.set_level(spdlog::level::off);
#endif
// TODO: Log leve: "start", "warn ", "error"
}
//------------------------------------------------------------------------------
void _Logger::trace(const char* format, ...) {
#if TRACE_IS_ON
va_list args;
va_start(args, format);
log(_ltTrace, format, args);
va_end(args);
#endif
}
//------------------------------------------------------------------------------
void _Logger::debug(const char* format, ...) {
#if DEBUG_IS_ON
va_list args;
va_start(args, format);
log(_ltDebug, format, args);
va_end(args);
#endif
}
//------------------------------------------------------------------------------
void _Logger::info(const char* format, ...) {
#if INFO_IS_ON
va_list args;
va_start(args, format);
log(_ltInfo, format, args);
va_end(args);
#endif
}
//------------------------------------------------------------------------------
void _Logger::startup(const char* format, ...) {
va_list args;
va_start(args, format);
log(_ltStartup, format, args);
va_end(args);
}
//------------------------------------------------------------------------------
void _Logger::warn(const char* format, ...) {
va_list args;
va_start(args, format);
log(_ltWarn, format, args);
va_end(args);
}
//------------------------------------------------------------------------------
void _Logger::error(const char* format, ...) {
va_list args;
va_start(args, format);
log(_ltError, format, args);
va_end(args);
}
//------------------------------------------------------------------------------
void _Logger::log(_LogType lt, const char* format, va_list& args) {
char buffer[2048];
vsnprintf(buffer, sizeof(buffer), format, args);
switch (lt) {
case _ltTrace:
m_log.trace(buffer);
break;
case _ltDebug:
m_log.debug(buffer);
break;
case _ltInfo:
m_log.info(buffer);
break;
case _ltStartup:
m_log.warn(buffer);
break;
case _ltWarn:
m_log.error(buffer);
break;
case _ltError:
m_log.critical(buffer);
break;
}
}
......@@ -19,104 +19,93 @@
* contact@openairinterface.org
*/
#ifndef __LOGGER_H
#define __LOGGER_H
#include <cstdarg>
#include <stdexcept>
#include <vector>
#define SPDLOG_LEVEL_NAMES \
{"trace", "debug", "info ", "start", "warn ", "error", "off "};
#define SPDLOG_ENABLE_SYSLOG
#include "spdlog/spdlog.h"
class LoggerException : public std::runtime_error {
public:
explicit LoggerException(const char* m) : std::runtime_error(m) {}
explicit LoggerException(const std::string& m) : std::runtime_error(m) {}
};
class _Logger {
public:
_Logger(
const char* category, std::vector<spdlog::sink_ptr>& sinks,
const char* pattern);
void trace(const char* format, ...);
void trace(const std::string& format, ...);
void debug(const char* format, ...);
void debug(const std::string& format, ...);
void info(const char* format, ...);
void info(const std::string& format, ...);
void startup(const char* format, ...);
void startup(const std::string& format, ...);
void warn(const char* format, ...);
void warn(const std::string& format, ...);
void error(const char* format, ...);
void error(const std::string& format, ...);
private:
_Logger();
enum _LogType { _ltTrace, _ltDebug, _ltInfo, _ltStartup, _ltWarn, _ltError };
void log(_LogType lt, const char* format, va_list& args);
spdlog::logger m_log;
};
#pragma once
#include "logger_base.hpp"
static const std::string ASYNC_CMD = "async_cmd";
static const std::string AMF_APP = "amf_app";
static const std::string CONFIG = "config";
static const std::string SYSTEM = "system";
static const std::string SCTP = "sctp";
static const std::string NAS_MM = "nas_mm";
static const std::string NGAP = "ngap";
static const std::string ITTI = "itti";
static const std::string AMF_N2 = "amf_n2";
static const std::string AMF_N1 = "amf_n1";
static const std::string AMF_SBI = "amf_sbi";
static const std::string AMF_SERVER_LOG = "amf_server";
class Logger {
public:
static void init(
const char* app, const bool log_stdout, const bool log_rot_file) {
singleton()._init(app, log_stdout, log_rot_file);
const std::string& name, const bool log_stdout, const bool log_rot_file) {
oai::logger::logger_registry::register_logger(
name, ASYNC_CMD, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, AMF_APP, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, CONFIG, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, SYSTEM, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, SCTP, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, NAS_MM, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, NGAP, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, ITTI, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, AMF_N2, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, AMF_N1, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, AMF_SBI, log_stdout, log_rot_file);
oai::logger::logger_registry::register_logger(
name, AMF_SERVER_LOG, log_stdout, log_rot_file);
}
static void init(
const std::string& app, const bool log_stdout, const bool log_rot_file) {
init(app.c_str(), log_stdout, log_rot_file);
static void set_level(spdlog::level::level_enum level) {
oai::logger::logger_registry::set_level(level);
}
static _Logger& async_cmd() { return *singleton().m_async_cmd; }
static _Logger& amf_app() { return *singleton().m_amf_app; }
static _Logger& config() { return *singleton().m_config; }
static _Logger& system() { return *singleton().m_system; }
static _Logger& sctp() { return *singleton().m_sctp; }
static _Logger& nas_mm() { return *singleton().m_nas_mm; }
static _Logger& ngap() { return *singleton().m_ngap; }
static _Logger& itti() { return *singleton().m_itti; }
static _Logger& amf_n2() { return *singleton().m_amf_n2; }
static _Logger& amf_n1() { return *singleton().m_amf_n1; }
static _Logger& amf_sbi() { return *singleton().m_amf_sbi; }
static _Logger& amf_server() { return *singleton().m_amf_server; }
private:
static Logger* m_singleton;
static Logger& singleton() {
if (!m_singleton) m_singleton = new Logger();
return *m_singleton;
static bool should_log(spdlog::level::level_enum level) {
return oai::logger::logger_registry::should_log(level);
}
Logger() {}
~Logger() {}
void _init(const char* app, const bool log_stdout, const bool log_rot_file);
std::vector<spdlog::sink_ptr> m_sinks;
std::string m_pattern;
_Logger* m_async_cmd;
_Logger* m_amf_app;
_Logger* m_config;
_Logger* m_system;
_Logger* m_sctp;
_Logger* m_nas_mm;
_Logger* m_ngap;
_Logger* m_itti;
_Logger* m_amf_n2;
_Logger* m_amf_n1;
_Logger* m_amf_sbi;
_Logger* m_amf_server;
static const oai::logger::printf_logger& async_cmd() {
return oai::logger::logger_registry::get_logger(ASYNC_CMD);
}
static const oai::logger::printf_logger& amf_app() {
return oai::logger::logger_registry::get_logger(AMF_APP);
}
static const oai::logger::printf_logger& config() {
return oai::logger::logger_registry::get_logger(CONFIG);
}
static const oai::logger::printf_logger& system() {
return oai::logger::logger_registry::get_logger(SYSTEM);
}
static const oai::logger::printf_logger& sctp() {
return oai::logger::logger_registry::get_logger(SCTP);
}
static const oai::logger::printf_logger& nas_mm() {
return oai::logger::logger_registry::get_logger(NAS_MM);
}
static const oai::logger::printf_logger& ngap() {
return oai::logger::logger_registry::get_logger(NGAP);
}
static const oai::logger::printf_logger& itti() {
return oai::logger::logger_registry::get_logger(ITTI);
}
static const oai::logger::printf_logger& amf_n2() {
return oai::logger::logger_registry::get_logger(AMF_N2);
}
static const oai::logger::printf_logger& amf_n1() {
return oai::logger::logger_registry::get_logger(AMF_N1);
}
static const oai::logger::printf_logger& amf_sbi() {
return oai::logger::logger_registry::get_logger(AMF_SBI);
}
static const oai::logger::printf_logger& amf_server() {
return oai::logger::logger_registry::get_logger(AMF_SERVER_LOG);
}
};
#endif
......@@ -32,16 +32,15 @@ void output_wrapper::print_buffer(
if (!app.compare("ngap")) Logger::ngap().debug(sink.c_str());
if (!app.compare("amf_server")) Logger::amf_server().debug(sink.c_str());
if (!app.compare("amf_sbi")) Logger::amf_sbi().debug(sink.c_str());
#if DEBUG_IS_ON
for (int i = 0; i < len; i++) printf("%02x ", buf[i]);
printf("\n");
#endif
if (Logger::should_log(spdlog::level::debug)) {
for (int i = 0; i < len; i++) printf("%02x ", buf[i]);
printf("\n");
}
}
//------------------------------------------------------------------------------
void output_wrapper::print_asn_msg(
const asn_TYPE_descriptor_t* td, const void* struct_ptr) {
#if DEBUG_IS_ON
asn_fprint(stdout, td, struct_ptr);
#endif
if (Logger::should_log(spdlog::level::debug))
asn_fprint(stdout, td, struct_ptr);
}
......@@ -19,7 +19,6 @@
# contact@openairinterface.org
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/itti)
include_directories(${SRC_TOP_DIR}/itti/msgs)
include_directories(${SRC_TOP_DIR}/common)
......@@ -35,6 +34,7 @@ include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka)
include_directories(${SRC_TOP_DIR}/secu_algorithms/nas_enc_int)
include_directories(${SRC_TOP_DIR}/utils)
include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
add_library (CONTEXTS STATIC
${CMAKE_CURRENT_SOURCE_DIR}/nas_context.cpp
......
......@@ -134,7 +134,7 @@ int _5GSMobileIdentity::Decode(uint8_t* buf, int len, bool is_iei) {
//------------------------------------------------------------------------------
int _5GSMobileIdentity::Encode5gGuti(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding 5G-GUTI IEI 0x%x", iei_);
Logger::nas_mm().debug("Encoding 5G-GUTI IEI 0x%x", iei_.value());
int encoded_size = 0;
// IEI and Length
......
......@@ -156,21 +156,21 @@ add_definitions(-DBSTRLIB_CAN_USE_STL=1 -DBSTRLIB_CAN_USE_IOSTREAM=1 -DBSTRLIB_T
if(STATIC_LINKING)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -fstack-protector-all -DMALLOC_CHECK_=3 -O0 -fno-omit-frame-pointer")
else (STATIC_LINKING)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -fstack-protector-all -DMALLOC_CHECK_=3 -O0 -fsanitize=address -fno-omit-frame-pointer")
endif(STATIC_LINKING)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2 -fno-omit-frame-pointer -s -DINFO_IS_ON=1 -DDEBUG_IS_ON=1")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -O2 -DINFO_IS_ON=1 ")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -Os -s -DTRACE_IS_ON=1 -DDEBUG_IS_ON=1 -DINFO_IS_ON=1 -DAUTH_ALG_ON=0")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2 -fno-omit-frame-pointer -s")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -O2 ")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -Os -s -DAUTH_ALG_ON=0")
if(STATIC_LINKING)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++17 -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++17 -g -fstack-protector-all -DMALLOC_CHECK_=3 -O0 -fno-omit-frame-pointer")
else(STATIC_LINKING)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++17 -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++17 -g -fstack-protector-all -DMALLOC_CHECK_=3 -O0 -fsanitize=address -fno-omit-frame-pointer")
endif(STATIC_LINKING)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -std=c++17 -O2 -fno-omit-frame-pointer -s -DINFO_IS_ON=1 -DDEBUG_IS_ON=1")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -std=c++17 -g -O2 -DINFO_IS_ON=1")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -std=c++17 -O2 -fno-omit-frame-pointer -s")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -std=c++17 -g -O2")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -std=c++17 -Os -s")
......@@ -311,7 +311,6 @@ ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/secu_algorithms/5gaka ${C
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/secu_algorithms/nas_enc_int ${CMAKE_CURRENT_BINARY_DIR}/secu_algorithms/nas_enc_int)
include_directories(${SRC_TOP_DIR}/oai-amf)
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/amf-app)
include_directories(${SRC_TOP_DIR}/itti)
include_directories(${SRC_TOP_DIR}/itti/msgs)
......@@ -335,20 +334,24 @@ include_directories(${SRC_TOP_DIR}/sbi/amf_server/model)
include_directories(${SRC_TOP_DIR}/sctp)
include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka)
include_directories(${SRC_TOP_DIR}/secu_algorithms/nas_enc_int)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
add_executable(amf
${SRC_TOP_DIR}/oai-amf/main.cpp
${SRC_TOP_DIR}/oai-amf/main.cpp
${SRC_TOP_DIR}/oai-amf/options.cpp
${SRC_TOP_DIR}/itti/itti.cpp
${SRC_TOP_DIR}/itti/itti_msg.cpp
)
## Common modules
include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger/logger.cmake)
IF(STATIC_LINKING)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
SET_TARGET_PROPERTIES(amf PROPERTIES LINK_SEARCH_END_STATIC 1)
# asan do not support static linking
SET(ASAN)
ENDIF(STATIC_LINKING)
ENDIF(STATIC_LINKING)
target_link_libraries(amf ${ASAN}
-Wl,--start-group 3GPP_COMMON_TYPES AMF CONTEXTS AMF_SCTP AMF_SECU_5GAKA AMF_SECU_NAS AMF_UTILS AMF_SBI_SERVER config++ sctp -Wl,--end-group pthread ${NETTLE_LIBRARIES} ${MySQL_LIBRARY} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} nghttp2_asio boost_system boost_thread boost_chrono ssl crypt gmp pistache curl)
target_link_libraries(amf ${ASAN}
-Wl,--start-group 3GPP_COMMON_TYPES AMF CONTEXTS AMF_SCTP AMF_SECU_5GAKA AMF_SECU_NAS AMF_UTILS AMF_SBI_SERVER config++ sctp fmt spdlog -Wl,--end-group pthread ${NETTLE_LIBRARIES} ${MySQL_LIBRARY} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} nghttp2_asio boost_system boost_thread boost_chrono ssl crypt gmp pistache curl)
......@@ -106,6 +106,7 @@ int main(int argc, char** argv) {
amf_cfg.load(Options::getlibconfigConfig());
amf_cfg.display();
Logger::set_level(amf_cfg.log_level);
itti_inst = new itti_mw();
itti_inst->start(amf_cfg.itti.itti_timer_sched_params);
......
......@@ -21,7 +21,6 @@
set(AMF_API_SERVER_DIR "${SRC_TOP_DIR}/sbi/amf_server")
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/amf-app)
include_directories(${SRC_TOP_DIR}/itti)
include_directories(${SRC_TOP_DIR}/itti/msgs)
......@@ -39,6 +38,7 @@ include_directories(${SRC_TOP_DIR}/sbi/amf_server)
include_directories(${SRC_TOP_DIR}/sbi/amf_server/api)
include_directories(${SRC_TOP_DIR}/sbi/amf_server/impl)
include_directories(${SRC_TOP_DIR}/sbi/amf_server/model)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
file(GLOB AMF_API_SERVER_src_files
${AMF_API_SERVER_DIR}/amf-http2-server.cpp
......@@ -47,8 +47,6 @@ file(GLOB AMF_API_SERVER_src_files
${AMF_API_SERVER_DIR}/api/*.cpp
${AMF_API_SERVER_DIR}/impl/*.cpp
)
add_library(AMF_SBI_SERVER STATIC
${AMF_API_SERVER_src_files})
......@@ -19,7 +19,6 @@
# contact@openairinterface.org
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/unicode)
include_directories(${SRC_TOP_DIR}/nas/common)
......@@ -27,6 +26,7 @@ include_directories(${SRC_TOP_DIR}/ngap/libngap)
include_directories(${SRC_TOP_DIR}/sctp)
include_directories(${SRC_TOP_DIR}/utils)
include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
add_library (AMF_SCTP STATIC
${CMAKE_CURRENT_SOURCE_DIR}/sctp_server.cpp
......
......@@ -19,7 +19,6 @@
# contact@openairinterface.org
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/unicode)
include_directories(${SRC_TOP_DIR}/nas/ies)
......@@ -28,7 +27,7 @@ include_directories(${SRC_TOP_DIR}/ngap/libngap)
include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka)
include_directories(${SRC_TOP_DIR}/utils)
include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
add_library (AMF_SECU_5GAKA STATIC
authentication_algorithms_with_5gaka.cpp
......
......@@ -178,10 +178,6 @@ void Authentication_5gaka::RijndaelEncrypt(
#if AUTH_ALG_ON
printf("end of round(%d)\n0x", 0);
#endif
#if DEBUG_IS_ON
for (int i = 0; i < 16; i++) printf("%x ", state[i & 0x3][i >> 2]);
printf("\n");
#endif
for (r = 1; r <= 9; r++) {
ByteSub(state);
......
......@@ -19,7 +19,6 @@
# contact@openairinterface.org
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/unicode)
include_directories(${SRC_TOP_DIR}/nas/ies)
......@@ -29,6 +28,7 @@ include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka)
include_directories(${SRC_TOP_DIR}/secu_algorithms/nas_enc_int)
include_directories(${SRC_TOP_DIR}/utils)
include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
add_library (AMF_SECU_NAS STATIC
nas_algorithms.cpp
......
......@@ -19,7 +19,6 @@
# contact@openairinterface.org
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/unicode)
include_directories(${SRC_TOP_DIR}/nas/common)
......@@ -30,6 +29,7 @@ include_directories(${SRC_TOP_DIR}/amf-app)
include_directories(${SRC_TOP_DIR}/itti)
include_directories(${SRC_TOP_DIR}/itti/msgs)
include_directories(${SRC_TOP_DIR}/sbi/amf_server/model)
include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger)
add_library (AMF_UTILS STATIC
${CMAKE_CURRENT_SOURCE_DIR}/backtrace.c
......
......@@ -72,11 +72,7 @@
} \
} while (0)
#if DEBUG_IS_ON
#define _ASSERT_FINAL_ _Assert_SegFault_
#else
#define _ASSERT_FINAL_ _Assert_Exit_
#endif
#define AssertFatal(cOND, ...) _Assert_(cOND, _ASSERT_FINAL_, ##__VA_ARGS__)
#define DevCheck(cOND, vALUE1, vALUE2, vALUE3) \
......
......@@ -26,10 +26,11 @@
*/
#include "thread_sched.hpp"
using namespace oai::logger;
//------------------------------------------------------------------------------
void util::thread_sched_params::apply(
const int task_id, _Logger& logger) const {
const int task_id, const oai::logger::printf_logger& logger) const {
if (cpu_id >= 0) {
cpu_set_t cpuset;
CPU_SET(cpu_id, &cpuset);
......
......@@ -41,7 +41,7 @@ class thread_sched_params {
int cpu_id;
int sched_policy;
int sched_priority;
void apply(const int task_id, _Logger& logger) const;
void apply(const int task_id, const oai::logger::printf_logger& logger) const;
};
} // namespace util
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment