Changeset 35 in libcf for trunk/src/cf_log.c
- Timestamp:
- 02/05/13 18:18:37 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_log.c
r34 r35 161 161 162 162 static int 163 CF_Log_Local_Push (CF_LOG_CTX * ctx,164 const char * buffer)165 {166 strncat (ctx->buffer + ctx->length,167 buffer,168 ctx->size - ctx->length);169 ctx->length = strlen (ctx->buffer);170 171 return CF_OK;172 }173 174 static int175 163 CF_Log_Local_Flush (CF_LOG_CTX * ctx) 176 164 { … … 184 172 } 185 173 174 /** 175 * 로그 데이터 처리 176 * 177 * @return 성공 시, CF_OK; 실패 시, 오류 코드 178 * 179 * @param ctx 로그 컨텍스트 180 * @param buffer 로그 데이터 181 * @param demandSize 로그 데이터 길이 182 * 183 * @author vfire 184 */ 185 /* static */int 186 CF_Log_Local_Push (CF_LOG_CTX * ctx, 187 const char * buffer, 188 const size_t demandSize) 189 { 190 if( ctx->size > 0 ) /* 버퍼단위 버퍼링.... */ 191 { 192 size_t writeSize; 193 size_t remainSize; 194 195 remainSize = demandSize; 196 while (remainSize) 197 { 198 writeSize = (ctx->size - ctx->length) < remainSize ? (ctx->size - ctx->length) : remainSize; 199 200 memcpy (ctx->buffer + ctx->length, buffer + demandSize - remainSize, writeSize); 201 ctx->length += writeSize; 202 203 if (ctx->length == ctx->size) 204 CF_Log_Local_Flush (ctx); 205 206 remainSize -= writeSize; 207 } 208 } 209 else /* flush되어야 함. */ 210 { 211 if (CF_File_Write (ctx->fd, buffer, demandSize) < 0) 212 return CF_ERROR_LOG_FLUSH; 213 } 214 215 return CF_OK; 216 } 217 218 /** 219 * 로그를 사용하기 위해 초기화 220 * 221 * @return 성공 시, CF_OK; 실패 시, 오류 코드 222 * 223 * @param logPool 아이디 넘버 최대 값 224 */ 186 225 int 187 226 CF_Log_Initialize (const int logPool) … … 201 240 } 202 241 242 /** 243 * 로그가 모두 사용된 후 자원 해제 244 * 245 * @return CF_OK 반환 246 */ 203 247 int 204 248 CF_Log_Finalize (void) … … 219 263 } 220 264 265 /** 266 * 로그 컨텍스트 생성 267 * 268 * @return 성공 시, 로그 컨텍스트; 실패 시, NULL 269 * 270 * @param path 로그 파일 경로 271 * @param memsize 로그 버퍼 크기 272 * 273 * @see CF_LOG_BUFFER_DEFAULT, CF_LOG_BUFFER_NO 274 */ 221 275 CF_Log_Ctx 222 276 CF_Log_CreateCtx (const char * path, … … 269 323 } 270 324 325 /** 326 * 로그 컨텍스트 해제 327 * 328 * @return 성공 시, CF_OK; 실패 시, 오류 코드 329 * 330 * @param ctx 로그 컨텍스트 331 */ 271 332 int 272 333 CF_Log_DestroyCtx (CF_Log_Ctx ctx) … … 300 361 } 301 362 363 /** 364 * 로그 컨텍스트에 멀티쓰레드 모드 설정 365 * 366 * @return 성공 시, CF_OK; 실패 시, 오류 코드 367 * 368 * @param ctx 로그 컨텍스트 369 */ 302 370 int 303 371 CF_Log_SetMultiThread (CF_Log_Ctx ctx) … … 314 382 } 315 383 384 /** 385 * 로그 컨텍스트에 멀티쓰레드 모드 설정 해제 386 * 387 * @return 성공 시, CF_OK; 실패 시, 오류 코드 388 * 389 * @param ctx 로그 컨텍스트 390 */ 316 391 int 317 392 CF_Log_UnsetMultiThread (CF_Log_Ctx ctx) … … 328 403 } 329 404 405 /** 406 * 로그 컨텍스트에 따라 로그 쓰기 407 * 408 * @return 성공 시, CF_OK; 실패 시, 오류 코드 409 * 410 * @param ctx 로그 컨텍스트 411 * @param prefix 로그의 프리픽스 문자열 412 * @param fmt 포맷 스트링 413 * @param ... 가변 인자 414 */ 330 415 int 331 416 CF_Log_Write (CF_Log_Ctx ctx, … … 335 420 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 336 421 va_list valist; 337 char buffer[ 4096] = {0x00,};422 char buffer[16 * 1024] = {0x00,}; 338 423 char datetime[CF_LOG_DATETIME_LENGTH + 1] = {0x00,}; 339 size_t length = 0;340 424 341 425 if (CHECK_INVALID_CTX (ctx)) … … 349 433 vsprintf (buffer + strlen (buffer), fmt, valist); 350 434 351 if (context->size == CF_LOG_BUFFER_NO) 352 { 353 context->buffer = buffer; 354 context->length = strlen (buffer); 355 356 CF_Log_Local_Flush (context); 357 358 context->buffer = NULL; 359 /* context->length = 0; // already did this in flush */ 360 } 361 else /* (context->size > 0) */ 362 { 363 length = context->size - context->length; 364 CF_Log_Local_Push (context, buffer); 365 366 if (context->length == context->size) 367 { 368 CF_Log_Local_Flush (context); 369 CF_Log_Local_Push (context, buffer + length); 370 } 371 } 435 CF_Log_Local_Push (context, buffer, strlen (buffer)); 372 436 373 437 va_end (valist); … … 377 441 } 378 442 443 /** 444 * 로그 버퍼의 데이터를 즉시 로그 파일에 쓰기 445 * 446 * @return 성공 시, CF_OK; 실패 시, 오류 코드 447 * 448 * @param ctx 로그 컨텍스트 449 */ 379 450 int 380 451 CF_Log_Flush (CF_Log_Ctx ctx) … … 392 463 } 393 464 465 /** 466 * 로그 컨텍스트에 아이디 넘버 할당<br /> 467 * 로그 기록 시, 아이디 넘버를 사용하면 해당 로그로 기록할 수 있음 468 * 469 * @return 성공 시, CF_OK; 실패 시, 오류 코드 470 * 471 * @param mapid 부여할 아이디 넘버 472 * @param ctx 로그 컨텍스트 473 * 474 * @remark 반드시 먼저 초기화 해야하며, 초기화 시에 주어진 번호보다 작은 아이디 넘버를 사용해야 함 475 * 476 * @see CF_LOG_OPEN, CF_Log_CreateCtx 477 */ 394 478 int 395 479 CF_Log_MapCtxID (const int mapid, … … 427 511 } 428 512 513 /** 514 * 아이디 넘버에 해당하는 로그를 닫고 해당하는 컨텍스트를 해제 515 * 516 * @return 성공 시, CF_OK; 실패 시, 오류 코드 517 * 518 * @param mapid 로그의 아이디 넘버 519 * 520 * @remark 아이디 넘버에 해당하는 컨텍스트가 해제되므로 주의 521 * 522 * @see CF_LOG_CLOSE, CF_Log_DestroyCtx 523 */ 429 524 int 430 525 CF_Log_UnmapCtxID (const int mapid) … … 445 540 } 446 541 542 /** 543 * 아이디 넘버에 해당하는 로그 컨텍스트를 얻기 544 * 545 * @return 성공 시, 로그 컨텍스트; 실패 시, NULL 546 * 547 * @param mapid 로그의 아이디 넘버 548 */ 447 549 CF_Log_Ctx 448 550 CF_Log_GetMappedCtx (const int mapid)
Note:
See TracChangeset
for help on using the changeset viewer.