/***************************************************************************
 *
 * Copyright (c) 2000, 2001 BalaBit IT Ltd, Budapest, Hungary
 *
 * This program 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: log.h,v 1.8.2.1.2.3 2001/09/19 19:22:17 bazsi Exp $
 *
 ***************************************************************************/

#ifndef ZORP_LOG_H_INCLUDED
#define ZORP_LOG_H_INCLUDED

#include <zorp/zorp.h>

#include <syslog.h>

extern unsigned int verbose_level;
extern unsigned int debug_flag;

extern gchar fake_session_id[256];

#define ZORP_SYSLOG_FACILITY LOG_LOCAL6

/*
void z_debug(int level, char *format, ...);
void z_warning(int level, char *format, ...);
void z_message(int level, char *format, ...);
void z_log(int level, GLogLevelFlags log_flags, char *msg); 
*/

#define z_debug(level, format, args...)   z_llog("core.debug", level, format, ##args)
#define z_warning(level, format, args...) z_llog("core.warning", level, format, ##args)
#define z_message(level, format, args...) z_llog("core.message", level, format, ##args)

void z_log_init(gchar *ls, gchar *syslog_name, gboolean use_syslog, gboolean log_tags);

void z_logv(gchar *class, int level, gchar *format, va_list ap);
void z_llog(gchar *class, int level, gchar *format, ...) __attribute__ ((format(printf, 3, 4)));
int z_log_register_class(gchar *class);
void z_log_set_fake_session_id(gchar *instance_name);
gboolean z_log_enabled(gchar *class, int level);
void z_log_clear_hash(void);


#define z_log(session_id, class, level, format, args...) \
  do \
    { \
      if (session_id == NULL) \
        z_llog(class, level, "%s: " format, fake_session_id , ##args); \
      else \
        z_llog(class, level, "%s: " format, (char *) session_id , ##args); \
    } \
  while (0)

#define z_proxy_log(self, class, level, format, args...) \
	z_log(((ZProxy *)self)->session_id, class, level, format,  ##args)

#if ENABLE_TRACE
  #define z_trace(session_id, args...) z_log(session_id , CORE_TRACE, 7, ##args)
  #define z_enter() z_log(NULL, CORE_TRACE, 7, "Enter into function: %s in line %d of file %s", __FUNCTION__, __LINE__, __FILE__)
  #define z_leave() z_log(NULL, CORE_TRACE, 7, "Leave from function: %s in line %d of file %s", __FUNCTION__, __LINE__, __FILE__)
  #define z_cp() z_log(NULL, CORE_TRACE, 7, "Check point in function: %s in line %d of file %s", __FUNCTION__, __LINE__, __FILE__)
#else
  #define z_trace(session_id, args...)
  #define z_enter()
  #define z_leave()
  #define z_cp()
#endif

#if ENABLE_TRACE
  #define z_proxy_trace(self, args...) z_proxy_log(self , CORE_TRACE, 7, ##args)
  #define z_proxy_enter(self) z_proxy_log(self, CORE_TRACE, 7, "Enter into function: %s in line %d of file %s", __FUNCTION__, __LINE__, __FILE__);
  #define z_proxy_leave(self) z_proxy_log(self, CORE_TRACE, 7, "Leave from function: %s in line %d of file %s", __FUNCTION__, __LINE__, __FILE__);
  #define z_proxy_cp(self) z_proxy_log(self, CORE_TRACE, 7, "Checkpoint in function: %s in line %d of file %s", __FUNCTION__, __LINE__, __FILE__);
#else
  #define z_proxy_trace(self, args...)
  #define z_proxy_enter(self)
  #define z_proxy_leave(self)
  #define z_proxy_cp(self)
#endif


#endif
