/****************************************************************************
 * This file is part of the project AqHome.
 * AqHome (c) by 2023 Martin Preuss, all rights reserved.
 *
 * The license for this file can be found in the file COPYING which you
 * should have received along with this file.
 ****************************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "aqhome/aqhome.h"

#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/logger.h>
#include <gwenhywfar/debug.h>

#include <stdlib.h>




int AQH_Init()
{
  int rv;
  const char *s;

  rv=GWEN_Init();
  if (rv) {
    DBG_ERROR_ERR(AQH_LOGDOMAIN, rv);
    return rv;
  }
  if (!GWEN_Logger_IsOpen(AQH_LOGDOMAIN))
    GWEN_Logger_Open(AQH_LOGDOMAIN, "aqhome", 0, GWEN_LoggerType_Console, GWEN_LoggerFacility_User);

  s=getenv("AQHOME_LOGLEVEL");
  if (s && *s) {
    GWEN_LOGGER_LEVEL ll;

    ll=GWEN_Logger_Name2Level(s);
    GWEN_Logger_SetLevel(AQH_LOGDOMAIN, ll);
  }
  else
    GWEN_Logger_SetLevel(AQH_LOGDOMAIN, GWEN_LoggerLevel_Notice);

  return 0;
}



int AQH_Fini()
{
  GWEN_Logger_Close(AQH_LOGDOMAIN);
  GWEN_Fini();
  return 0;
}




