DirectResult direct_log_init( DirectLog *log, const char *param ) { switch (log->type) { case DLT_STDERR: return init_stderr( log ); case DLT_FILE: return init_file( log, param ); case DLT_UDP: return init_udp( log, param ); default: break; } return DR_UNSUPPORTED; }
DirectResult direct_log_create( DirectLogType type, const char *param, DirectLog **ret_log ) { DirectResult ret = DR_INVARG; DirectLog *log; log = D_CALLOC( 1, sizeof(DirectLog) ); if (!log) return D_OOM(); log->type = type; switch (type) { case DLT_STDERR: ret = init_stderr( log ); break; case DLT_FILE: ret = init_file( log, param ); break; case DLT_UDP: ret = init_udp( log, param ); break; } if (ret) D_FREE( log ); else { direct_util_recursive_pthread_mutex_init( &log->lock ); D_MAGIC_SET( log, DirectLog ); *ret_log = log; } return ret; }