<commit_before>#pragma once

#include "assert.h"

#include "dlt_user.h"

#include "ivi-logging-common.h"

namespace logging {

class DltLogData;

class DltContextClass : public DltContext {

public:
	typedef DltLogData LogDataType;

	DltContextClass() {
	}

	~DltContextClass() {
		dlt_unregister_context(this);
	}

	void setParentContext(LogContextCommon& context) {
		m_context = &context;
	}

	bool isEnabled(LogLevel logLevel) const;

	static DltLogLevelType getDLTLogLevel(LogLevel level) {
		DltLogLevelType v = DLT_LOG_DEFAULT;
		switch (level) {
		case LogLevel::Debug : v = DLT_LOG_DEBUG; break;
		case LogLevel::Info : v = DLT_LOG_INFO; break;
		case LogLevel::Warning : v = DLT_LOG_WARN; break;
		case LogLevel::Fatal : v = DLT_LOG_FATAL; break;
		case LogLevel::Error : v = DLT_LOG_ERROR; break;
		case LogLevel::Verbose : v = DLT_LOG_VERBOSE; break;
		case LogLevel::None : v = DLT_LOG_OFF; break;
		default : v = DLT_LOG_DEFAULT; break;
		}
		return v;
	}

	void registerContext() {
		if ( !isAppRegistered() ) {
			registerApp( s_pAppLogContext->m_id.c_str(), s_pAppLogContext->m_description.c_str() );
		}
		//		auto code =
		dlt_register_context( this, m_context->getID(), m_context->getDescription() );
		//		assert(code == 0);
		//		m_isInitialized = true;
		//	}

	}

	static bool& isAppRegistered() {
		static bool m_appRegistered = false;
		return m_appRegistered;
	}

	/**
	 * Register the application.
	 */
	static void registerApp(const char* id, const char* description) {
		pid_t pid = getpid();
		char descriptionWithPID[1024];
		snprintf(descriptionWithPID, sizeof(descriptionWithPID), "PID:%i / %s", pid, description);

		auto dltCode = dlt_register_app(id, descriptionWithPID);

		// TODO : The piece of code below would be useful if the DLT library didn't always return 0
		if (dltCode != 0 ) {
			char pidAsHexString[5];
			snprintf(pidAsHexString, sizeof(pidAsHexString), "%X", pid);
			dltCode = dlt_register_app(pidAsHexString, descriptionWithPID);
		}
		isAppRegistered() = true;

		// TODO : caution is needed when forking a process if the connection to the DLT daemon is active.
		// We can probably use pthread_atfork() to disconnect before the fork, and reconnect after
//		int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));

	}

private:
	LogContextCommon* m_context = nullptr;

};


class DltLogData : public LogData, public DltContextData {

public:
	typedef DltContextClass ContextType;

	DltLogData() {
	}

	/**
	 * Enable or disable the output of source file information (file name, function name, line number)
	 */
	void setEnableSourceCodeLocationInfo(bool enabled) {
		m_enableSourceCodeLocationInfo = enabled;
	}

	/**
	 * Enable or disable the output of additional information about the thread generating the log
	 */
	void setEnableThreadInfo(bool enabled) {
		m_enableThreadInfo = enabled;
	}

	void init(DltContextClass& context, LogInfo& data) {
		m_data = &data;
		m_context = &context;
		auto dltLogLevel = m_context->getDLTLogLevel( m_data->getLogLevel() );
		m_enabled = (dlt_user_log_write_start(m_context, this, dltLogLevel) >= 0);
	}<commit_msg>Fix DLT log level check<commit_after>#pragma once

#include "assert.h"

#include "dlt_user.h"

#include "ivi-logging-common.h"

namespace logging {

class DltLogData;

class DltContextClass : public DltContext {

public:
	typedef DltLogData LogDataType;

	DltContextClass() {
	}

	~DltContextClass() {
		dlt_unregister_context(this);
	}

	void setParentContext(LogContextCommon& context) {
		m_context = &context;
	}

	bool isEnabled(LogLevel logLevel) const;

	static DltLogLevelType getDLTLogLevel(LogLevel level) {
		DltLogLevelType v = DLT_LOG_DEFAULT;
		switch (level) {
		case LogLevel::Debug : v = DLT_LOG_DEBUG; break;
		case LogLevel::Info : v = DLT_LOG_INFO; break;
		case LogLevel::Warning : v = DLT_LOG_WARN; break;
		case LogLevel::Fatal : v = DLT_LOG_FATAL; break;
		case LogLevel::Error : v = DLT_LOG_ERROR; break;
		case LogLevel::Verbose : v = DLT_LOG_VERBOSE; break;
		case LogLevel::None : v = DLT_LOG_OFF; break;
		default : v = DLT_LOG_DEFAULT; break;
		}
		return v;
	}

	void registerContext() {
		if ( !isAppRegistered() ) {
			registerApp( s_pAppLogContext->m_id.c_str(), s_pAppLogContext->m_description.c_str() );
		}
		//		auto code =
		dlt_register_context( this, m_context->getID(), m_context->getDescription() );
		//		assert(code == 0);
		//		m_isInitialized = true;
		//	}

	}

	static bool& isAppRegistered() {
		static bool m_appRegistered = false;
		return m_appRegistered;
	}

	/**
	 * Register the application.
	 */
	static void registerApp(const char* id, const char* description) {
		pid_t pid = getpid();
		char descriptionWithPID[1024];
		snprintf(descriptionWithPID, sizeof(descriptionWithPID), "PID:%i / %s", pid, description);

		auto dltCode = dlt_register_app(id, descriptionWithPID);

		// TODO : The piece of code below would be useful if the DLT library didn't always return 0
		if (dltCode != 0 ) {
			char pidAsHexString[5];
			snprintf(pidAsHexString, sizeof(pidAsHexString), "%X", pid);
			dltCode = dlt_register_app(pidAsHexString, descriptionWithPID);
		}
		isAppRegistered() = true;

		// TODO : caution is needed when forking a process if the connection to the DLT daemon is active.
		// We can probably use pthread_atfork() to disconnect before the fork, and reconnect after
//		int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));

	}

private:
	LogContextCommon* m_context = nullptr;

};


class DltLogData : public LogData, public DltContextData {

public:
	typedef DltContextClass ContextType;

	DltLogData() {
	}

	/**
	 * Enable or disable the output of source file information (file name, function name, line number)
	 */
	void setEnableSourceCodeLocationInfo(bool enabled) {
		m_enableSourceCodeLocationInfo = enabled;
	}

	/**
	 * Enable or disable the output of additional information about the thread generating the log
	 */
	void setEnableThreadInfo(bool enabled) {
		m_enableThreadInfo = enabled;
	}

	void init(DltContextClass& context, LogInfo& data) {
		m_data = &data;
		m_context = &context;
		auto dltLogLevel = m_context->getDLTLogLevel( m_data->getLogLevel() );
		m_enabled = (dlt_user_log_write_start(m_context, this, dltLogLevel) > 0);
	}
{'fraction_non_alphanumeric': 0.11040508339952343, 'fraction_numerical': 0.002859412231930103, 'mean_word_length': 4.489102005231038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4194935', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2126, 'n_words': 552}