source: libcf/trunk/src/cf_log.c@ 125

Last change on this file since 125 was 125, checked in by cheese, 11 years ago

#1 fix mutex bugs

File size: 12.5 KB
RevLine 
[23]1/**
[119]2 * \file cf_log.c
3 * \author myusgun <myusgun@gmail.com>
4 * \author vfire
[117]5 *
[123]6 * \brief ·Î±× ±¸Çö
[11]7 */
[50]8#if defined(_WIN32) || defined(_WIN64)
[14]9# define _USE_32BIT_TIME_T
[86]10# if (_MSC_VER >= 1400)
11# define localtime _localtime32
12# endif
[14]13#endif
14
[11]15#include "cf_log.h"
[12]16#include "cf_file.h"
[11]17#include "cf_thread.h"
[12]18#include "cf_local.h"
[40]19#include "cf_error.h"
[11]20
[12]21#include <stdio.h>
22#include <stdlib.h>
[11]23#include <string.h>
[12]24#include <stdarg.h>
25#include <time.h>
[11]26
[50]27#if defined(_WIN32) || defined(_WIN64)
[13]28# include <Windows.h>
[50]29#else
[12]30# include <sys/time.h>
[50]31#endif
[11]32
[85]33#define ASSERT_CTX(__ctx) \
34 if (__ctx == NULL) \
35 return CF_ERROR_LOG_INVALID_CTX
36
37#define ASSERT_INIT() \
38 if (gLogArray.ctxPool == NULL || \
39 gLogArray.ctxSize <= 0 ) \
40 return CF_ERROR_LOG_NOT_INITIALIZE
41
42#define ASSERT_MAPID(__mapid) \
43 if (gLogArray.ctxSize <= __mapid) \
44 return CF_ERROR_LOG_INVALID_MAPID
45
46#define ASSERT_MAPPED_CTX(__mapid) \
47 if (gLogArray.ctxPool[__mapid] != NULL) \
48 return CF_ERROR_LOG_ALREADY_MAPPED_ID
49
50#define ASSERT_NOT_MAPPED_CTX(__mapid) \
51 if (gLogArray.ctxPool[__mapid] == NULL) \
52 return CF_ERROR_LOG_NOT_MAPPED_ID
53
[42]54#define LOG_BUFFER_DEFAULT_SIZE 128 * 1024
[12]55
[51]56#define LOG_DATETIME_LENGTH sizeof ("0000-00-00 00:00:00.000") - 1
[34]57
[123]58/** ·Î±× ÄÁÅؽºÆ® (Opaque) */
[40]59typedef void * CF_Log_Ctx;
60
[12]61typedef struct __cf_util_datetime__
62{
63 int year;
64 int month;
65 int day;
66 int week; /* SUN:0 ~ SAT:6 */
67
68 int hour;
69 int min;
70 int sec;
71 int usec;
[109]72} CF_LOG_DATETIME;
[12]73
[123]74/** ·Î±× ÄÁÅؽºÆ® (CF_Log_CtxÀÇ ±¸Çö) */
[122]75typedef struct __cf_log_ctx__
76{
[109]77 char path[NAME_LENGTH + 1];
78 int fd;
79 char * buffer;
80 size_t size; /* entire size of buffer */
81 size_t length; /* data length in current */
82 CF_Mutex_Ctx mutex;
83} CF_LOG_CTX;
[11]84
[122]85typedef struct __cf_log_array__
86{
[12]87 CF_Log_Ctx * ctxPool;
88 int ctxSize;
[109]89} CF_LOG_ARRAY;
[11]90
[51]91static CF_LOG_ARRAY gLogArray;
[11]92
[12]93#if defined(_WIN32) || defined(_WIN64)
[66]94/* {{{ */
[12]95struct timezone
96{
[66]97 int tz_minuteswest; /* minutes W of Greenwich */
98 int tz_dsttime; /* type of dst correction */
[12]99};
100
[66]101int gettimeofday (struct timeval *tv, struct timezone *tz)
[12]102{
[66]103 FILETIME ft;
104 unsigned __int64 buf =0;
[38]105 //static int tzflag = 0;
[12]106
107 if (NULL != tv)
108 {
[66]109 GetSystemTimeAsFileTime (&ft);
[12]110
[66]111 buf |= ft.dwHighDateTime;
[67]112 buf <<= 32;
[66]113 buf |= ft.dwLowDateTime;
[12]114
[66]115 if (buf)
[12]116 {
[66]117 buf /= 10;
118 buf -= ((369 * 365 + 89) * (unsigned __int64) 86400) * 1000000;
[12]119 }
120
[66]121 tv->tv_sec = (long)(buf / 1000000UL);
122 tv->tv_usec = (long)(buf % 1000000UL);
[12]123 }
124
[38]125 /*
[12]126 if (NULL != tz)
127 {
128 if (!tzflag)
129 {
130 _tzset();
131 tzflag++;
132 }
133
134 // Adjust for the timezone west of Greenwich
135 tz->tz_minuteswest = _timezone / 60;
136 tz->tz_dsttime = _daylight;
137 }
[38]138 */
[12]139
140 return 0;
141}
[66]142/* }}} */
[50]143#endif
[12]144
[23]145static int
[30]146CF_Log_Local_GetTime (CF_LOG_DATETIME * dt)
[11]147{
[12]148 struct timeval timeVal;
149 struct tm * timeSt;
150
151 gettimeofday (&timeVal, NULL);
[13]152 timeSt = localtime ((const time_t *)&timeVal.tv_sec);
[12]153
154 dt->year = timeSt->tm_year + 1900;
155 dt->month = timeSt->tm_mon + 1;
156 dt->day = timeSt->tm_mday;
157 dt->week = timeSt->tm_wday;
158
159 dt->hour = timeSt->tm_hour;
160 dt->min = timeSt->tm_min;
161 dt->sec = timeSt->tm_sec;
162
163 dt->usec = (int) timeVal.tv_usec;
164
165 return CF_OK;
166}
167
[23]168static int
[12]169CF_Log_Local_GetTimeString (char * buffer)
170{
[30]171 CF_LOG_DATETIME dt;
[12]172 CF_Log_Local_GetTime (&dt);
173
[42]174 snprintf (buffer, LOG_DATETIME_LENGTH,
[14]175 "%02d-%02d-%02d %02d:%02d:%02d.%03d",
176 dt.year, dt.month, dt.day,
177 dt.hour, dt.min, dt.sec, dt.usec);
178
[12]179 return CF_OK;
180}
181
[23]182static int
[12]183CF_Log_Local_Flush (CF_LOG_CTX * ctx)
184{
185 if (CF_File_Write (ctx->fd, ctx->buffer, ctx->length) < 0)
186 return CF_ERROR_LOG_FLUSH;
187
188 ctx->length = 0;
189
190 return CF_OK;
191}
192
[35]193/**
[123]194 * ·Î±× µ¥ÀÌÅÍ Ã³¸®
[35]195 *
[123]196 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]197 *
[123]198 * \param ctx ·Î±× ÄÁÅؽºÆ®
199 * \param buffer ·Î±× µ¥ÀÌÅÍ
200 * \param demandSize ·Î±× µ¥ÀÌÅÍ ±æÀÌ
[35]201 *
[119]202 * \author vfire
[35]203 */
204/* static */int
205CF_Log_Local_Push (CF_LOG_CTX * ctx,
206 const char * buffer,
207 const size_t demandSize)
208{
[40]209 int result = CF_OK;
210
[123]211 if (ctx->size > 0) /* ¹öÆÛ´ÜÀ§ ¹öÆÛ¸µ.... */
[35]212 {
213 size_t writeSize;
214 size_t remainSize;
215
216 remainSize = demandSize;
217 while (remainSize)
218 {
219 writeSize = (ctx->size - ctx->length) < remainSize ? (ctx->size - ctx->length) : remainSize;
220
221 memcpy (ctx->buffer + ctx->length, buffer + demandSize - remainSize, writeSize);
222 ctx->length += writeSize;
223
224 if (ctx->length == ctx->size)
225 CF_Log_Local_Flush (ctx);
226
227 remainSize -= writeSize;
228 }
229 }
[123]230 else /* flushµÇ¾î¾ß ÇÔ. */
[35]231 {
[38]232 ctx->buffer = (char *)buffer;
233 ctx->length = demandSize;
234
[40]235 result = CF_Log_Local_Flush (ctx);
[35]236 }
237
[40]238 return result;
239}
240
241/**
[123]242 * ·Î±× ÄÁÅؽºÆ®¿¡ ¸ÖƼ¾²·¹µå ¸ðµå ¼³Á¤
[40]243 *
[123]244 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[40]245 *
[123]246 * \param ctx ·Î±× ÄÁÅؽºÆ®
[40]247 *
[119]248 * \see CF_Log_UnsetMultiThread
[40]249 */
250static int
251CF_Log_SetMultiThread (CF_Log_Ctx ctx)
252{
253 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
254
[85]255 ASSERT_CTX (ctx);
[40]256
[109]257 if (CF_Mutex_CreateCtx (&context->mutex) < 0)
[40]258 return CF_ERROR_LOG_SET_MULTITHREAD;
259
[35]260 return CF_OK;
261}
262
263/**
[123]264 * ·Î±× ÄÁÅؽºÆ®¿¡ ¸ÖƼ¾²·¹µå ¸ðµå ¼³Á¤ ÇØÁ¦
[35]265 *
[123]266 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[40]267 *
[123]268 * \param ctx ·Î±× ÄÁÅؽºÆ®
[40]269 *
[119]270 * \see CF_Log_SetMultiThread
[40]271 */
272static int
273CF_Log_UnsetMultiThread (CF_Log_Ctx ctx)
274{
275 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
276
[85]277 ASSERT_CTX (ctx);
[40]278
[122]279 if (CF_Mutex_DestoryCtx (context->mutex) < 0)
[40]280 return CF_ERROR_LOG_UNSET_MULTITHREAD;
281
[122]282 context->mutex = NULL;
283
[40]284 return CF_OK;
285}
286
287/**
[123]288 * ·Î±× ÄÁÅؽºÆ®¿¡ µû¶ó ·Î±× ¾²±â
[40]289 *
[123]290 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]291 *
[123]292 * \param ctx ·Î±× ÄÁÅؽºÆ®
293 * \param prefix ·Î±×ÀÇ ÇÁ¸®ÇȽº ¹®ÀÚ¿­
294 * \param fmt Æ÷¸Ë ½ºÆ®¸µ
295 * \param ... °¡º¯ ÀÎÀÚ
[35]296 */
[40]297static int
298CF_Log_WriteCtx (CF_Log_Ctx ctx,
299 const char * prefix,
300 const char * fmt,
301// ...)
302 va_list valist)
[12]303{
[107]304#define BUF_LEN 16 * 1024
[40]305 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
306// va_list valist;
[107]307 char buffer[BUF_LEN + 1] = {0x00,};
[42]308 char datetime[LOG_DATETIME_LENGTH + 1] = {0x00,};
[107]309 int length = 0;
[11]310
[85]311 ASSERT_CTX (ctx);
[11]312
[125]313 CF_Mutex_Lock (context->mutex);
[40]314// va_start (valist, fmt);
315
316 CF_Log_Local_GetTimeString (datetime);
[107]317 length = snprintf (buffer, BUF_LEN, "[%s][%s] ", datetime, prefix);
318 vsnprintf (&buffer[length], BUF_LEN - (size_t)length, fmt, valist);
[40]319
320 CF_Log_Local_Push (context, buffer, strlen (buffer));
321
322// va_end (valist);
[125]323 CF_Mutex_Unlock (context->mutex);
[40]324
[11]325 return CF_OK;
326}
327
[35]328/**
[123]329 * ·Î±× ¹öÆÛÀÇ µ¥ÀÌÅ͸¦ Áï½Ã ·Î±× ÆÄÀÏ¿¡ ¾²±â
[35]330 *
[123]331 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[40]332 *
[123]333 * \param ctx ·Î±× ÄÁÅؽºÆ®
[35]334 */
[40]335static int
336CF_Log_FlushCtx (CF_Log_Ctx ctx)
[11]337{
[40]338 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
[19]339
[85]340 ASSERT_CTX (ctx);
[40]341
[125]342 CF_Mutex_Lock (context->mutex);
[40]343 CF_Log_Local_Flush (context);
[125]344 CF_Mutex_Unlock (context->mutex);
[40]345
346 return CF_OK;
347}
348
349/**
[123]350 * ·Î±× ÄÁÅؽºÆ® ÇØÁ¦
[40]351 *
[123]352 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[40]353 *
[123]354 * \param ctx ·Î±× ÄÁÅؽºÆ®
[40]355 */
356static int
357CF_Log_DestroyCtx (CF_Log_Ctx ctx)
358{
359 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
360
[85]361 ASSERT_CTX (ctx);
[40]362
363 if (context->size > 0)
[19]364 {
[40]365 CF_Log_FlushCtx (ctx);
366 free (context->buffer);
367 context->buffer = NULL;
368 context->size = 0;
[19]369 }
370
[40]371 CF_File_Close (context->fd);
[19]372
[122]373 CF_Mutex_DestoryCtx (context->mutex);
[45]374 context->mutex = NULL;
[11]375
376 return CF_OK;
377}
[12]378
[35]379/**
[123]380 * ·Î±× ÄÁÅؽºÆ® »ý¼º
[35]381 *
[123]382 * \return ¼º°ø ½Ã, ·Î±× ÄÁÅؽºÆ®; ½ÇÆÐ ½Ã, NULL
[35]383 *
[123]384 * \param ctx ·Î±× ÄÁÅؽºÆ® ÁÖ¼Ò
385 * \param path ·Î±× ÆÄÀÏ °æ·Î
386 * \param memsize ·Î±× ¹öÆÛ Å©±â
[35]387 *
[119]388 * \see CF_LOG_DEFAULT_BUFFER, CF_LOG_NO_BUFFER
[35]389 */
[40]390static int
[122]391CF_Log_CreateCtx (CF_Log_Ctx * ctx,
392 const char * path,
393 const int memsize)
[12]394{
395 int result = 0;
[93]396 int fileFlag = CF_FILE_CREATE|CF_FILE_WRITE|CF_FILE_APPEND;
[103]397 int size = (memsize == CF_LOG_DEFAULT_BUFFER)
[42]398 ? LOG_BUFFER_DEFAULT_SIZE
[12]399 : memsize;
[87]400
[12]401 CF_LOG_CTX * context = NULL;
402
403 if (path == NULL)
[40]404 return CF_ERROR_LOG_INVALID_ARGS;
[12]405
406 TRY
407 {
408 context = (CF_LOG_CTX *) calloc (sizeof (CF_LOG_CTX), 1);
409 if (context == NULL)
410 {
[109]411 result = CF_ERROR_LOG_CREATE_CTX;
[12]412 TRY_BREAK;
413 }
414
[93]415 context->fd = CF_File_Open (path, fileFlag);
[12]416 if (context->fd < 0)
417 {
[40]418 result = CF_ERROR_LOG_CREATE_FILE;
[12]419 TRY_BREAK;
420 }
[46]421 snprintf (context->path, sizeof (context->path) -1, "%s", path);
[12]422
423 if (size > 0)
424 {
425 context->buffer = (char *) calloc ((size_t) size + 1, 1);
426 if (context->buffer == NULL)
427 {
[40]428 result = CF_ERROR_LOG_ALLOCATE_BUFFER;
[12]429 TRY_BREAK;
430 }
431 context->size = (size_t) size;
432 }
[87]433
434 *ctx = (CF_Log_Ctx) context;
[12]435 }
436 CATCH_IF (result < 0)
437 {
438 CF_Log_DestroyCtx ((CF_Log_Ctx) context);
439 }
440
[93]441 return result;
[12]442}
443
[35]444/**
[123]445 * ·Î±× ÄÁÅؽºÆ®¿¡ ¾ÆÀ̵ð ³Ñ¹ö ÇÒ´ç<br />
446 * ·Î±× ±â·Ï ½Ã, ¾ÆÀ̵ð ³Ñ¹ö¸¦ »ç¿ëÇϸé ÇØ´ç ·Î±×·Î ±â·ÏÇÒ ¼ö ÀÖÀ½
[35]447 *
[123]448 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]449 *
[123]450 * \param mapid ºÎ¿©ÇÒ ¾ÆÀ̵ð ³Ñ¹ö
451 * \param ctx ·Î±× ÄÁÅؽºÆ®
[40]452 *
[123]453 * \remarks ¹Ýµå½Ã ¸ÕÀú ÃʱâÈ­ ÇؾßÇϸç, ÃʱâÈ­ ½Ã¿¡ ÁÖ¾îÁø ¹øÈ£º¸´Ù ÀÛÀº ¾ÆÀ̵ð ³Ñ¹ö¸¦ »ç¿ë
[40]454 *
[119]455 * \see CF_LOG_OPEN, CF_Log_CreateCtx
[35]456 */
[40]457static int
458CF_Log_MapCtxID (const int mapid,
459 const CF_Log_Ctx ctx)
[12]460{
[85]461 ASSERT_INIT ();
462 ASSERT_MAPID (mapid);
463 ASSERT_MAPPED_CTX (mapid);
[12]464
[51]465 gLogArray.ctxPool[mapid] = ctx;
[40]466
[12]467 return CF_OK;
468}
469
[35]470/**
[123]471 * ¾ÆÀ̵ð ³Ñ¹ö¿¡ ÇØ´çÇÏ´Â ·Î±×¸¦ ´Ý°í ÇØ´çÇÏ´Â ÄÁÅؽºÆ®¸¦ ÇØÁ¦
[35]472 *
[123]473 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]474 *
[123]475 * \param mapid ·Î±×ÀÇ ¾ÆÀ̵ð ³Ñ¹ö
[40]476 *
[123]477 * \remarks ¾ÆÀ̵ð ³Ñ¹ö¿¡ ÇØ´çÇÏ´Â ÄÁÅؽºÆ®°¡ ÇØÁ¦µÇ¹Ç·Î ÁÖÀÇ
[40]478 *
[119]479 * \see CF_LOG_CLOSE, CF_Log_DestroyCtx
[35]480 */
[40]481static int
482CF_Log_UnmapCtxID (const int mapid)
[19]483{
[85]484 ASSERT_INIT ();
485 ASSERT_MAPID (mapid);
486 ASSERT_NOT_MAPPED_CTX (mapid);
[19]487
[51]488 CF_Log_DestroyCtx (gLogArray.ctxPool[mapid]);
[19]489
[51]490 free (gLogArray.ctxPool[mapid]);
491 gLogArray.ctxPool[mapid] = NULL;
[19]492
493 return CF_OK;
494}
495
[35]496/**
[123]497 * ¾ÆÀ̵ð ³Ñ¹ö¿¡ ÇØ´çÇÏ´Â ·Î±× ÄÁÅؽºÆ®¸¦ ¾ò±â
[35]498 *
[123]499 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]500 *
[123]501 * \param mapid ·Î±×ÀÇ ¾ÆÀ̵ð ³Ñ¹ö
502 * \param ctx ·Î±× ÄÁÅؽºÆ® ¹ÞÀ» ÁÖ¼Ò
[35]503 */
[40]504static int
505CF_Log_GetMappedCtx (const int mapid,
506 CF_Log_Ctx * ctx)
[19]507{
[85]508 ASSERT_INIT ();
509 ASSERT_MAPID (mapid);
510 ASSERT_NOT_MAPPED_CTX (mapid);
[19]511
[51]512 *ctx = gLogArray.ctxPool[mapid];
[19]513
514 return CF_OK;
515}
516
[35]517/**
[123]518 * ·Î±×¸¦ »ç¿ëÇϱâ À§ÇØ ÃʱâÈ­
[35]519 *
[123]520 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]521 *
[123]522 * \param poolSize ·Î±× Ç® Å©±â·Î, ·Î±× ¾ÆÀ̵ð ³Ñ¹öÀÇ ÃÖ´ë °ª
[35]523 */
[19]524int
[108]525CF_Log_Initialize (const int poolSize)
[12]526{
[51]527 memset (&gLogArray, 0x00, sizeof (CF_LOG_ARRAY));
[12]528
[101]529 if (poolSize > 0)
[40]530 {
[51]531 gLogArray.ctxPool =
[101]532 (CF_Log_Ctx *) calloc ((size_t) poolSize, sizeof (CF_Log_Ctx));
[51]533 if (gLogArray.ctxPool == NULL)
[40]534 return CF_ERROR_LOG_INITIALIZE;
[101]535 gLogArray.ctxSize = poolSize;
[40]536 }
[12]537
[40]538 return CF_OK;
539}
[12]540
[40]541/**
[123]542 * ·Î±×°¡ ¸ðµÎ »ç¿ëµÈ ÈÄ ÀÚ¿ø ÇØÁ¦
[40]543 *
[123]544 * \return CF_OK ¹Ýȯ
[40]545 */
546int
547CF_Log_Finalize (void)
548{
549 int mapid = 0;
[12]550
[51]551 for (mapid = 0 ; mapid < gLogArray.ctxSize ; mapid++)
[40]552 {
553 CF_Log_UnmapCtxID (mapid);
554 }
[12]555
[51]556 if (gLogArray.ctxPool != NULL)
557 free (gLogArray.ctxPool);
[12]558
[51]559 memset (&gLogArray, 0x00, sizeof (CF_LOG_ARRAY));
[40]560
[12]561 return CF_OK;
562}
563
[35]564/**
[123]565 * ·Î±× ¿­±â
[35]566 *
[123]567 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]568 *
[123]569 * \param mapid ·Î±×ÀÇ ¾ÆÀ̵ð ³Ñ¹ö
570 * \param path ·Î±× ÆÄÀÏ °æ·Î
571 * \param memsize ·Î±× ¹öÆÛ Å©±â
[40]572 *
[119]573 * \see CF_LOG_DEFAULT_BUFFER, CF_LOG_NO_BUFFER
[35]574 */
[12]575int
[40]576CF_Log_Open (const int mapid,
577 const char * path,
578 const int memsize)
[12]579{
[40]580 int result = 0;
581 CF_Log_Ctx ctx = NULL;
[12]582
[122]583 result = CF_Log_CreateCtx (&ctx, path, memsize);
[40]584 if (result < 0)
585 return result;
[12]586
[40]587 result = CF_Log_MapCtxID (mapid, ctx);
[85]588 if (result < 0)
589 CF_Log_DestroyCtx (ctx);
[12]590
[40]591 return result;
[12]592}
[19]593
[35]594/**
[123]595 * ·Î±× ´Ý±â
[35]596 *
[123]597 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]598 *
[123]599 * \param mapid ·Î±×ÀÇ ¾ÆÀ̵ð ³Ñ¹ö
[40]600 */
601int
602CF_Log_Close (const int mapid)
603{
604 return CF_Log_UnmapCtxID (mapid);
605}
606
607/**
[123]608 * ·Î±× ¹öÆÛÀÇ µ¥ÀÌÅ͸¦ Áï½Ã ·Î±× ÆÄÀÏ¿¡ ¾²±â
[35]609 *
[123]610 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]611 *
[123]612 * \param mapid ·Î±×ÀÇ ¾ÆÀ̵ð ³Ñ¹ö
[35]613 */
[19]614int
[98]615CF_Log_Flush (const int mapid)
[19]616{
[40]617 int result = 0;
618 CF_Log_Ctx ctx = NULL;
[19]619
[40]620 result = CF_Log_GetMappedCtx (mapid, &ctx);
621 if (result < 0)
[25]622 return result;
[19]623
[98]624 result = CF_Log_FlushCtx (ctx);
[19]625
[40]626 return result;
[19]627}
628
[35]629/**
[123]630 * ·Î±× ÄÁÅؽºÆ®¿¡ ¸ÖƼ¾²·¹µå ¸ðµå ¼³Á¤
[35]631 *
[123]632 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[35]633 *
[123]634 * \param mapid ·Î±×ÀÇ ¾ÆÀ̵ð ³Ñ¹ö
635 * \param flag ¼³Á¤/ÇØÁ¦ bool Ç÷¡±×
[98]636 *
[119]637 * \see CF_BOOL
[35]638 */
[19]639int
[98]640CF_Log_SetMT (const int mapid,
641 const CF_BOOL flag)
[19]642{
[40]643 int result = 0;
644 CF_Log_Ctx ctx = NULL;
[19]645
[40]646 result = CF_Log_GetMappedCtx (mapid, &ctx);
647 if (result < 0)
648 return result;
[19]649
[98]650 result = (flag) ? CF_Log_SetMultiThread (ctx) :
651 CF_Log_UnsetMultiThread (ctx);
[19]652
[40]653 return result;
[19]654}
655
[35]656/**
[123]657 * ·Î±× ¾²±â
[98]658 *
[123]659 * \return ¼º°ø ½Ã, CF_OK; ½ÇÆÐ ½Ã, ¿À·ù ÄÚµå
[98]660 *
[123]661 * \param mapid ·Î±×ÀÇ ¾ÆÀ̵ð ³Ñ¹ö
662 * \param prefix ·Î±×ÀÇ ÇÁ¸®ÇȽº ¹®ÀÚ¿­
663 * \param fmt Æ÷¸Ë ½ºÆ®¸µ
664 * \param ... °¡º¯ ÀÎÀÚ
[98]665 */
666int
667CF_Log_Write (const int mapid,
668 const char * prefix,
669 const char * fmt, ...)
670{
[40]671 int result = 0;
672 CF_Log_Ctx ctx = NULL;
[98]673 va_list valist;
[19]674
[40]675 result = CF_Log_GetMappedCtx (mapid, &ctx);
676 if (result < 0)
677 return result;
678
[98]679 va_start (valist, fmt);
680 result = CF_Log_WriteCtx (ctx, prefix, fmt, valist);
681 va_end (valist);
[40]682
683 return result;
[19]684}
Note: See TracBrowser for help on using the repository browser.