


#pragma once

/* $Header: https://svn.mpia.de/gulli/TwiceAsNice/branch/unstable/TwiceAsNice/nice/src/libNice/Nice/Log/Macros.h 14124 2016-12-19 14:21:21Z mathar $
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <sys/types.h>
#include <unistd.h>
#include <Nice/Log/External.h>
#include <Nice/Log/Stream.h>

#include "shins_util_f.h"

#ifdef DEBUG
# define NICE_DEBUG
# define NICE_TRACE
# define NICE_USER
#endif

#ifdef TRACE
# define NICE_TRACE
#endif

#ifndef LOG_NAME
#define LOG_NAME Nice::Name
#endif


//#define NICE_LOG_NAME(x) Nice::setLogName(x)
//#define LOG_LEVEL(x) Nice::createStdOut(); Nice::StdOut->setLogLevel(x)
//#define NICE_LOG_USER(x) Nice::createStdOut();  Nice::StdOut->setUserLogLevel(x)
//#define LOG_OBJ(x) Nice::createStdOut(); Nice::StdOut->setFunc(x)
//#define LOG_FILE(x) Nice::createStdOut(); Nice::StdOut->setFile(x)


//#define LOG_STD Nice::createStdOut(); Nice::StdOut->setFunc(new Nice::StdLogFunction())
//#define LOG_EXT Nice::createStdOut(); Nice::StdOut->setFunc(new Nice::ExtLogFunction())
//#define LOG_COLOR Nice::createStdOut(); Nice::StdOut->setFunc(new Nice::StdColorLogFunction())
//#define LOG_STDCOL Nice::createStdOut();  Nice::StdOut->setFunc(new Nice::StdColorLogFunction())
//#define LOG_EXTCOL Nice::createStdOut();  Nice::StdOut->setFunc(new Nice::ExtColorLogFunction())


//#define LOG(z, y) Nice::createStdOut(); if(z <= Nice::StdOut->m_level) {
//                           Nice::Guard guard(Nice::StdOut->m_mutex);
//                           Nice::StdOut->log(z, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << y
//                            << std::endl; }


#define F_LLOG(y) Nice::createStdOut(); if(Nice::LFATAL <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LFATAL, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}
#define A_LLOG(y) Nice::createStdOut(); if(Nice::LALERT <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LALERT, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}
#define C_LLOG(y) Nice::createStdOut(); if(Nice::LCRITICAL <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LCRITICAL, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}
#define E_LLOG(y) Nice::createStdOut(); if(Nice::LERROR <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LERROR, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}
#define W_LLOG(y) Nice::createStdOut(); if(Nice::LWARNING <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LWARNING, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}
#define N_LLOG(y) Nice::createStdOut(); if(Nice::LNOTICE <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LNOTICE, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}
#define I_LLOG(y) Nice::createStdOut(); if(Nice::LINFO <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LINFO, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}
#define I_LLOG(y) Nice::createStdOut(); if(Nice::LINFO <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LINFO, __BASE_FILE__, __LINE__, __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}


#ifndef NICE_USER
#define U1_LLOG(y);
#define U2_LLOG(y);
#define U3_LLOG(y);
#define U4_LLOG(y);
#define U5_LLOG(y);
#define U6_LLOG(y);
#define U7_LLOG(y);
#define U8_LLOG(y);
#define U9_LLOG(y);
#else

#define U1_LLOG(y) Nice::createStdOut(); if(Nice::LUSER1 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LUSER1, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }

#define U2_LLOG(y) Nice::createStdOut(); if(Nice::LUSER2 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LUSER2, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }

#define U3_LLOG(y) Nice::createStdOut(); if(Nice::LUSER3 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LUSER3, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }

#define U4_LLOG(y) Nice::createStdOut(); if(Nice::LUSER4 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LUSER4, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }

#define U5_LLOG(y) Nice::createStdOut(); if(Nice::LUSER5 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LUSER5, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }

#define U6_LLOG(y) Nice::createStdOut(); int shinslog_level = 0; if(Nice::LUSER6 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           if(Nice::StdOut->m_level >= Nice::LUSER8)shinslog_level = shins::util::shinslog::call(); \
                           Nice::StdOut->log(Nice::LUSER6, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y << " : " << shinslog_level <<std::endl; }

#define U7_LLOG(y) Nice::createStdOut(); if(Nice::LUSER7 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LUSER7, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }

#define U8_LLOG(y) Nice::createStdOut(); if(Nice::LUSER8 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           std::stringstream yy; \
                           yy << y; \
                           if(!yy.str().empty()) \
                           {Nice::StdOut->log(Nice::LUSER8, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl;}; \
                           shins::util::shinslog::back(shinslog_level);}

#define U9_LLOG(y) Nice::createStdOut(); if(Nice::LUSER9 <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LUSER9, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }

#endif


#ifndef NICE_DEBUG
#define D_LLOG(y);
#else
#define D_LLOG(y) Nice::createStdOut(); if(Nice::LDEBUG <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LDEBUG, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }
#endif


#ifndef NICE_TRACE
#define T_LLOG(y);
#else
#define T_LLOG(y) Nice::createStdOut(); if(Nice::LTRACE <= Nice::StdOut->m_level) { \
                           Nice::Guard guard(Nice::StdOut->m_mutex); \
                           Nice::StdOut->log(Nice::LTRACE, __BASE_FILE__, __LINE__,  __FUNCTION__,  LOG_NAME) << shins::util::shinslog::log << y <<std::endl; }
#endif


//
