Index: trunk/test/test.c
===================================================================
--- trunk/test/test.c	(revision 38)
+++ trunk/test/test.c	(revision 40)
@@ -25,5 +25,6 @@
 CF_Debug_CallStack	gDebugCallstack;
 
-CF_Log_Ctx			gLogCtx;
+#define LOG_SOCKET		0
+#define LOG_MT			1
 
 const char * file = "./log.txt";
@@ -36,5 +37,5 @@
 	for (i = 0 ; i < 100000 ; i++)
 	{
-		CF_Log_Write (gLogCtx, "LOG_MT", "[%d] multi-threadedlogging test %d\n", th, i);
+		CF_Log_Write (LOG_MT, "LOG_MT", "[%d] multi-threadedlogging test %d\n", th, i);
 	}
 
@@ -51,47 +52,35 @@
 
 	/* initialize */
-	CF_Log_Initialize (10);
-
-	/* context {{{ */
-	gLogCtx = CF_Log_CreateCtx (file, CF_LOG_BUFFER_DEFAULT);
-	if (gLogCtx == NULL)
+	if (CF_Log_Initialize (10) < 0)
+	{
+		fprintf (stderr, "failed to init. log\n");
+		return ;
+	}
+
+	for (i = 0 ; i < 10 ; i++)
+	{
+		sprintf (idname, "logid%d.txt", i);
+		if (CF_Log_Open (i, idname, CF_LOG_BUFFER_NO) < 0)
+			fprintf (stderr, "failed to open log\n");
+	}
+
+	for (i = 0 ; i < 10 ; i++)
+	{
+		for (j = 0 ; j < 10000 ; j++)
+		{
+			int result = CF_Log_Write (i, "LOG_ID_TEST", "turn %d\n", j); 
+			if (result < 0)
+				fprintf (stderr, "failed to write log %d\n", result);
+		}
+
+		if (CF_Log_Close (i) < 0)
+			fprintf (stderr, "failed to close log\n");
+	}
+
+	/* mt {{{ */
+	if (CF_Log_Open (LOG_MT, "log_mt.txt", CF_LOG_BUFFER_DEFAULT) < 0)
 		CF_DEBUG_PRINT (stderr, "create log ctx error\n");
 
-	for (i = 0 ; i < 1000 ; i++)
-		CF_Log_Write (gLogCtx, "LOG_TEST", "turn %d\n", i);
-
-	CF_DEBUG_CALLSTACK_POP (gDebugCtx, &gDebugCallstack);
-
-	CF_Log_Write (gLogCtx, message,
-							"here is the end of function [file:%s line:%d func:%s]\n",
-							gDebugCallstack.file,
-							gDebugCallstack.line,
-							gDebugCallstack.function);
-
-	CF_Log_DestroyCtx (gLogCtx);
-	/* }}} context */
-
-	/* id {{{ */
-	for (i = 0 ; i < 10 ; i++)
-	{
-		sprintf (idname, "logid%d.txt", i);
-		CF_LOG_OPEN (i, idname, CF_LOG_BUFFER_NO);
-	}
-
-	for (i = 0 ; i < 10 ; i++)
-	{
-		for (j = 0 ; j < 10000 ; j++)
-			CF_LOG_WRITE (i, "LOG_ID_TEST", "turn %d\n", j);
-
-		CF_LOG_CLOSE (i);
-	}
-	/* }}} id */
-
-	/* mt {{{ */
-	gLogCtx = CF_Log_CreateCtx ("log_mt.txt", CF_LOG_BUFFER_DEFAULT);
-	if (gLogCtx == NULL)
-		CF_DEBUG_PRINT (stderr, "create log ctx error\n");
-
-	if (CF_Log_SetMultiThread (gLogCtx) < 0)
+	if (CF_Log_SetMT (LOG_MT, CF_TRUE) < 0)
 		CF_DEBUG_PRINT (stderr, "set multi-threading mode error\n");
 
@@ -111,6 +100,4 @@
 			CF_DEBUG_PRINT (stderr, "failed to join %dth thread\n", i);
 	}
-
-	CF_Log_DestroyCtx (gLogCtx);
 	/* }}} mt */
 
@@ -184,5 +171,5 @@
 		return (CF_THREAD_RETURN)-1;
 	}
-	CF_Log_Write (gLogCtx, "SERVER", "accepted\n");
+	CF_Log_Write (LOG_SOCKET, "SERVER", "accepted\n");
 
 	for (i = 0 ; i < 100 ; i++)
@@ -193,5 +180,5 @@
 			return (CF_THREAD_RETURN)-2;
 		}
-		CF_Log_Write (gLogCtx, "SERVER", "recv {%s}\n", buf);
+		CF_Log_Write (LOG_SOCKET, "SERVER", "recv {%s}\n", buf);
 
 		if (CF_Socket_Send (clntsock, buf, recvd) < 0)
@@ -199,5 +186,5 @@
 			return (CF_THREAD_RETURN)-3;
 		}
-		CF_Log_Write (gLogCtx, "SERVER", "resp {%s}\n", buf);
+		CF_Log_Write (LOG_SOCKET, "SERVER", "resp {%s}\n", buf);
 	}
 
@@ -224,5 +211,5 @@
 		return (CF_THREAD_RETURN)-1;
 	}
-	CF_Log_Write (gLogCtx, "CLIENT", "connected\n");
+	CF_Log_Write (LOG_SOCKET, "CLIENT", "connected\n");
 
 	for (i = 0 ; i < 100 ; i++)
@@ -233,5 +220,5 @@
 			return (CF_THREAD_RETURN)-2;
 		}
-		CF_Log_Write (gLogCtx, "CLIENT", "sent {%s}\n", buf);
+		CF_Log_Write (LOG_SOCKET, "CLIENT", "sent {%s}\n", buf);
 
 		memset (buf, 0x00, sizeof (buf));
@@ -242,5 +229,5 @@
 			return (CF_THREAD_RETURN)-3;
 		}
-		CF_Log_Write (gLogCtx, "CLIENT", "recv {%s}\n", buf);
+		CF_Log_Write (LOG_SOCKET, "CLIENT", "recv {%s}\n", buf);
 	}
 
@@ -260,9 +247,14 @@
 
 	/*------------------------------------------------------------*/
-	gLogCtx = CF_Log_CreateCtx ("socket.txt", CF_LOG_BUFFER_DEFAULT);
-	if (gLogCtx == NULL)
+	if (CF_Log_Initialize (1) < 0)
+	{
+		fprintf (stderr, "failed to init. log\n");
+		return ;
+	}
+
+	if (CF_Log_Open (LOG_SOCKET, "socket.txt", CF_LOG_BUFFER_DEFAULT) < 0)
 		CF_DEBUG_PRINT (stderr, "failed to open log\n");
 
-	CF_Log_Write (gLogCtx, "LOG_MULTITHREAD", "multi-threaded logging test with socket\n");
+	CF_Log_Write (LOG_SOCKET, "LOG_MULTITHREAD", "multi-threaded logging test with socket\n");
 
 	if (CF_Socket_Initialize () < 0)
@@ -271,5 +263,5 @@
 		return ;
 	}
-	CF_Log_Write (gLogCtx, "SOCKET", "socket initialized\n");
+	CF_Log_Write (LOG_SOCKET, "SOCKET", "socket initialized\n");
 
 	sock = CF_Socket_Server (PORT, 5);
@@ -279,5 +271,5 @@
 		return ;
 	}
-	CF_Log_Write (gLogCtx, "SOCKET", "socket ready\n");
+	CF_Log_Write (LOG_SOCKET, "SOCKET", "socket ready\n");
 
 	if (CF_Socket_SetOption (sock, SO_REUSEADDR, &reuse, sizeof (reuse)) < 0)
@@ -286,5 +278,5 @@
 		return ;
 	}
-	CF_Log_Write (gLogCtx, "SOCKET", "set socket option\n");
+	CF_Log_Write (LOG_SOCKET, "SOCKET", "set socket option\n");
 
 	for (iter = 0 ; iter < THREAD_POOL ; iter++)
@@ -295,5 +287,5 @@
 			return ;
 		}
-		CF_Log_Write (gLogCtx, "SOCKET", "create server thread-%d\n", iter);
+		CF_Log_Write (LOG_SOCKET, "SOCKET", "create server thread-%d\n", iter);
 	}
 
@@ -306,5 +298,5 @@
 			return ;
 		}
-		CF_Log_Write (gLogCtx, "SOCKET", "create client thread-%d\n", iter);
+		CF_Log_Write (LOG_SOCKET, "SOCKET", "create client thread-%d\n", iter);
 	}
 
@@ -313,5 +305,5 @@
 		CF_Thread_Join (&tid[iter]);
 		CF_Thread_Release (&tid[iter]);
-		CF_Log_Write (gLogCtx, "SOCKET", "join server thread-%d\n", iter);
+		CF_Log_Write (LOG_SOCKET, "SOCKET", "join server thread-%d\n", iter);
 	}
 
@@ -320,5 +312,7 @@
 	CF_Socket_Finalize ();
 
-	CF_Log_DestroyCtx (gLogCtx);
+	CF_Log_Close (LOG_SOCKET);
+
+	CF_Log_Finalize ();
 	/*------------------------------------------------------------*/
 }
