#include "logging.h"

#define LOGPATH_MAX_LEN			256

static char log_path [LOGGRP_MAX][LOGPATH_MAX_LEN];

static FILE *log_fd [LOGGRP_MAX];

void chinput_log_init (void)
{
	char cnt;

	strncpy (log_path [LOG_GRP_XIM], "/tmp/chinput-xim.log",
			sizeof (LOGPATH_MAX_LEN));
	strncpy (log_path [LOG_GRP_DOCK], "/tmp/chinput-dock.log",
			sizeof (LOGPATH_MAX_LEN));
	strncpy (log_path [LOG_GRP_IMM], "/tmp/chinput-imm.log",
			sizeof (LOGPATH_MAX_LEN));
	strncpy (log_path [LOG_GRP_ENC], "/tmp/chinput-enc.log",
			sizeof (LOGPATH_MAX_LEN));

	for (cnt = 0; cnt < LOGGRP_MAX; cnt++)
	{
		log_fd [cnt] = fopen (log_path [cnt], "a");
	}
}

void chinput_log_print (log_grp_t type, const char *fmt, ...)
{
	va_list arg_list;

	va_start (arg_list, fmt);

	vfprintf (log_fd [type], fmt, arg_list);

	va_end (arg_list);
}

void chinput_log_close (void)
{
	char cnt;

	for (cnt = 0; cnt < LOGGRP_MAX; cnt++)
	{
		fclose (log_fd [cnt]);
	}
}
