コード例 #1
0
ファイル: log.cpp プロジェクト: jeffrey-lee/AppleSeed
int NLog::startup( const char* _log_path, int _level, int _daemon_mode )
{
	if ( start() < 0 )
		return -1;

	if ( ! _log_path )
		return -1;
    
	strncpy( log_path_, _log_path, sizeof(log_path_) );

	daemon_mode_ = _daemon_mode;
	if( !daemon_mode_ )
	{
		for ( int i = 0; i < MAX_LOG_TYPE; i++ )
			log_[i] = stdout;
	}
	else
	{
		log_[ LOG_TYPE_FATAL ] = open_log_file( "fatal" );
		log_[ LOG_TYPE_EMERGENCY ] = open_log_file( "emergency" );
		log_[ LOG_TYPE_ERROR ] = open_log_file( "error" );
		log_[ LOG_TYPE_LOG ] = open_log_file( "log" );
		log_[ LOG_TYPE_DEBUG ] = open_log_file( "debug" );
	}

    set_level( _level );

	return 0;
}
コード例 #2
0
ファイル: log.c プロジェクト: darknightghost/mcserverd
bool log_init()
{
	//Creat log directory
	if(mkdir(LOG_DIR, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
		if(errno != EEXIST) {
			return false;
		}

	}

	//Read config
	max_size = cfg_get_log_file_size();
	max_num = cfg_get_log_file_num();

	//Open log file
	ssh_fp = open_log_file(SSH_LOG_NAME, &ssh_log_num, &ssh_size);

	if(ssh_fp == NULL) {
		return false;
	}

	minecraft_fp = open_log_file(MC_LOG_NAME, &mc_log_num, &mc_size);

	if(minecraft_fp == NULL) {
		fclose(ssh_fp);
		return false;
	}

	//Initialize mutex
	pthread_mutex_init(&ssh_mutex, NULL);
	pthread_mutex_init(&mc_mutex, NULL);
	return true;
}
コード例 #3
0
ファイル: log.c プロジェクト: johan--/netdata
void open_all_log_files() {
    // disable stdin
    open_log_file(STDIN_FILENO, &stdin, "/dev/null", NULL);

    open_log_file(STDOUT_FILENO, &stdout, stdout_filename, &output_log_syslog);
    open_log_file(STDERR_FILENO, &stderr, stderr_filename, &error_log_syslog);
    stdaccess_fd = open_log_file(stdaccess_fd, &stdaccess, stdaccess_filename, &access_log_syslog);
}
コード例 #4
0
ファイル: log.c プロジェクト: johan--/netdata
void reopen_all_log_files() {
    if(stdout_filename)
        open_log_file(STDOUT_FILENO, &stdout, stdout_filename, &output_log_syslog);

    if(stderr_filename)
        open_log_file(STDERR_FILENO, &stderr, stderr_filename, &error_log_syslog);

    if(stdaccess_filename)
        stdaccess_fd = open_log_file(stdaccess_fd, &stdaccess, stdaccess_filename, &access_log_syslog);
}
コード例 #5
0
ファイル: bossan_ext.c プロジェクト: henteko/bossan
static VALUE
bossan_access_log(VALUE self, VALUE args)
{   
  log_path = StringValuePtr(args);

  if(log_fd > 0){
    close(log_fd);
  }

  if(!strcasecmp(log_path, "stdout")){
    log_fd = 1;
    return Qnil;
  }

  if(!strcasecmp(log_path, "stderr")){
    log_fd = 2;
    return Qnil;
  }

  log_fd = open_log_file(log_path);

  if(log_fd < 0){
    rb_raise(rb_eTypeError, "not open file. %s", log_path);
  }
  return Qnil;
}
コード例 #6
0
static gboolean
write_log_for_event (CkLogEvent *event)
{
        GString *str;
        FILE    *file;
        int      fd;

        str = g_string_new (NULL);

        ck_log_event_to_string (event, str);

        if (! open_log_file (DEFAULT_LOG_FILENAME, &fd, &file)) {
                exit (1);
        }

        if (file != NULL) {
                int rc;

                rc = fprintf (file, "%s\n", str->str);
                if (rc <= 0) {
                        g_warning ("Record was not written to disk (%s)",
                                   g_strerror (errno));
                }
        } else {
                g_warning ("Log file not open for writing");
        }

        g_string_free (str, TRUE);

        return TRUE;
}
コード例 #7
0
ファイル: perfmon.c プロジェクト: abduld/Parboil
void perf_end(const char* kname) {
  if (!enabled) return;
  int i, n;
  prctl(PR_TASK_PERF_EVENTS_DISABLE);

  static int first_time = 1;
  if (first_time) {
    first_time = 0;
    char name[128];
    for (n = 0; n < g_nthreads; n++) {
      sprintf (name, mxpa_profile_log, n);
      FILE* fp = fopen(name, "w");
      fclose(fp);
    }
  }

  char name[128];
  for (n = 0; n < g_nthreads; n++) {
    sprintf (name, mxpa_profile_log, n);
    FILE* fp = open_log_file(name);
    perf_event_desc_t *fds = g_fds[n];
    print_counts(fds, num_fds, kname, fp);
    for (i = 0; i < num_fds; i++) close(fds[i].fd);
    perf_free_fds(fds, num_fds);
    g_fds[n] = fds = NULL;
    fclose(fp);
  }
}
コード例 #8
0
ファイル: srs_app_log.cpp プロジェクト: 13916688528/srs
int SrsFastLog::on_reload_log_tank()
{
    int ret = ERROR_SUCCESS;
    
    if (!_srs_config) {
        return ret;
    }

    bool tank = log_to_file_tank;
    log_to_file_tank = _srs_config->get_log_tank_file();

    if (tank) {
        return ret;
    }

    if (!log_to_file_tank) {
        return ret;
    }

    if (fd > 0) {
        ::close(fd);
    }
    open_log_file();
    
    return ret;
}
コード例 #9
0
ファイル: oor.c プロジェクト: biels/oor
JNIEXPORT jint JNICALL Java_org_openoverlayrouter_noroot_OOR_1JNI_oor_1start
  (JNIEnv *env, jobject thisObj, jint vpn_tun_fd, jstring storage_path)
{
    oor_dev_type_e dev_type;
    jintArray fd_list;
    uint32_t iseed = 0;  /* initial random number generator */
    pid_t pid = 0;    /* child pid */
    pid_t sid = 0;
    char log_file[1024];
    const char *path = NULL;
    lisp_xtr_t *tunnel_router;
    memset (log_file,0,sizeof(char)*1024);

    initial_setup();
    jni_init(env,thisObj);

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    oor_timers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    lctrl = ctrl_create();

    /* Detect the data plane type */
    data_plane_select();

    /** parse config and create ctrl_dev **/
    /* obtain the configuration file */
    path = (*env)->GetStringUTFChars(env, storage_path, 0);
    config_file = calloc(1024, sizeof(char));
    strcat(config_file,path);
    strcat(config_file,"oor.conf");
    strcat(log_file,path);
    strcat(log_file,"oor.log");
    (*env)->ReleaseStringUTFChars(env, storage_path, path);
    open_log_file(log_file);
    if (parse_config_file()!=GOOD){
        exit_cleanup();
        close(vpn_tun_fd);
        return (BAD);
    }
    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        OOR_LOG(LDBG_2, "Configuring data plane");
        tunnel_router = CONTAINER_OF(ctrl_dev, lisp_xtr_t, super);
        data_plane->datap_init(dev_type, tr_get_encap_type(tunnel_router), vpn_tun_fd);
        OOR_LOG(LDBG_1, "Data plane initialized");

    }
    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
     if (!ctrl_dev) {
         OOR_LOG(LDBG_1, "device NULL");
         return (BAD);
     }
     return (GOOD);
}
コード例 #10
0
ファイル: stats.c プロジェクト: AVGirl/dynamorio
void
kstat_init()
{
    kstat_frequency_per_msec = get_timer_frequency();
    kstat_ignore_context_switch = KSTAT_OUTLIER_THRESHOLD_MS * kstat_frequency_per_msec;

    LOG(GLOBAL, LOG_STATS, 1, "Processor speed: "UINT64_FORMAT_STRING"MHz\n",
        kstat_frequency_per_msec/1000);

    /* FIXME: There is no check for TSC feature and whether CR4.TSD is set
     * so we can read it at CPL 3
     */

    if (!DYNAMO_OPTION(kstats))
        return;

    kstat_init_variables(&process_kstats);
#ifdef DEBUG
    process_kstats_outfile = GLOBAL;
#else
    /* Open a process-wide kstats file. open_thread_private_file() does the
     * job when passed the appropriate basename (2nd arg).
     */
    process_kstats_outfile =
        open_log_file(kstats_main_logfile_name(), NULL, 0);
#endif
}
コード例 #11
0
ファイル: log.c プロジェクト: cs470Group/sdn-controller
/**
 * Initializes the Logger. This creates a log file to which messages
 * are written.
 *
 * @param ident name of the log file, used as an identifier.
 * @param log_directory the directory in which log file is created.
 * @param type log output type.
 * @return true on success; false otherwise.
 */
bool
init_log( const char *ident, const char *directory, logging_type type ) {
  assert( ident != NULL );
  assert( directory != NULL );

  pthread_mutex_lock( &mutex );

  // set_logging_level() may be called before init_log().
  // level = -1 indicates that logging level is not set yet.
  if ( level < 0 || level > LOG_DEBUG ) {
    level = LOG_INFO;
  }
  char *level_string = getenv( "LOGGING_LEVEL" );
  if ( level_string != NULL ) {
    set_logging_level( level_string );
  }

  set_ident_string( ident );
  set_log_directory( directory );
  output = type;
  if ( output & LOGGING_TYPE_FILE ) {
    fd = open_log_file( false );
  }
  if ( output & LOGGING_TYPE_SYSLOG ) {
    open_log_syslog();
  }

  initialized = true;

  pthread_mutex_unlock( &mutex );

  return true;
}
コード例 #12
0
ファイル: stats.c プロジェクト: AVGirl/dynamorio
void
kstat_thread_init(dcontext_t *dcontext)
{
    thread_kstats_t *new_thread_kstats;
    if (!DYNAMO_OPTION(kstats))
        return;                 /* dcontext->thread_kstats stays NULL */

    /* allocated on thread heap - use global if timing initialization matters */
    new_thread_kstats = HEAP_TYPE_ALLOC(dcontext, thread_kstats_t, ACCT_STATS, UNPROTECTED);
    LOG(THREAD, LOG_STATS, 2, "thread_kstats="PFX" size=%d\n", new_thread_kstats,
        sizeof(thread_kstats_t));
    /* initialize any thread stats bookkeeping fields before assigning to dcontext */
    kstat_init_variables(&new_thread_kstats->vars_kstats);
    /* add a dummy node to save one branch in UPDATE_CURRENT_COUNTER */
    new_thread_kstats->stack_kstats.depth = 1;

    new_thread_kstats->thread_id = get_thread_id();
#ifdef DEBUG
    new_thread_kstats->outfile_kstats = THREAD;
#else
    new_thread_kstats->outfile_kstats =
        open_log_file(kstats_thread_logfile_name(), NULL, 0);
#endif
    dcontext->thread_kstats = new_thread_kstats;

    /* need to do this in a thread after it's initialized */
    kstat_calibrate();

    KSTART_DC(dcontext, thread_measured);

    LOG(THREAD, LOG_STATS, 2, "threads_started\n");
}
コード例 #13
0
ファイル: hist.c プロジェクト: fcovatti/iccp
int main (int argc, char ** argv){
	int i;
	signal(SIGINT, sigint_handler);
	
	if (open_log_file() != 0) {
		printf("Error opening log file\n");
		return -1;
	}

	if(create_db_comm() <0){
		LOG_MESSAGE("could not create db comm\n");
		return -1;
	}

	if(create_hist_comm() <0){
		LOG_MESSAGE("could not create hist comm\n");
		finish_with_error(con);
		return -1;
	}
	
	while(running){
		check_packet();
	}
	LOG_MESSAGE("Total Receive %d - A:%d   D:%d   E:%d (%d) | Error: %d\n", (digital_msgs+analog_msgs+events_msgs),
			analog_msgs, digital_msgs, events_msgs, should_be_type_30, error_msgs);

	close(hist_socket_receive);
	mysql_close(con);
	return 0;
}
コード例 #14
0
ファイル: bossan_ext.c プロジェクト: henteko/bossan
static int
write_log(const char *new_path, int fd, const char *data, size_t len)
{
  int openfd;
  flock(fd, LOCK_EX);
    
  if(write(fd, data, len) < 0){
    flock(fd, LOCK_UN);
    //reopen
    openfd = open_log_file(new_path);
    if(openfd < 0){
      //fail
      return -1; 
    }
    flock(openfd, LOCK_EX);
    if(write(openfd, data, len) < 0){
      flock(openfd, LOCK_UN);
      // write fail
      return -1;
    }
    flock(openfd, LOCK_UN);
    return openfd;
  }
  flock(fd, LOCK_UN);
  return fd;
}
コード例 #15
0
static BOOL check_head_valid( void )
{
    fs_handle_type  file;

    file = open_log_file();
    if( file == FS_NULL_HANDLE )
    {
        return FALSE;
    }

    // 로그크기(LOG_SIZE) 동일한지 검사
    if( get_value( file, LOG_SIZE_POS, 6 ) != LOG_SIZE )
    {
        goto _fail;
    }

    // 로그최대개수(MAX_LOG) 일치하는지 검사
    if( get_value( file, MAX_POS, 4 ) != MAX_LOG )
    {
        goto _fail;
    }

    pantech_fclose( file );
    return TRUE;

_fail:
    pantech_fclose( file );
    pantech_fremove( LOG_PATH );
    return FALSE;
}
コード例 #16
0
ファイル: logging.c プロジェクト: hagrid-the-developer/stud
void msg(const int level, const char *fmt, ...) {
    static const size_t time_part_size = (4 + 1 + 2 + 1 + 2) + 1 + (2 + 1 + 2 + 1 + 2); // YYYY.MM.DD HH:MM:SS

    const int file_fd = open_log_file();
    const int fd = file_fd >= 0 ? file_fd : 2;

    va_list lst, lst2;
    va_start(lst, fmt);
    va_copy(lst2, lst);

    const int isize = vsnprintf(NULL, 0, fmt, lst);
    const intmax_t pid = (intmax_t) getpid();
    const size_t pid_part_size = snprintf(NULL, 0, "[%jd]", pid);

    char buf[1 + 1 + time_part_size + 1 + pid_part_size + 1 + isize + 1];

    size_t sz = 0;
    buf[0] = level;
    buf[1] = '\t';
    sz = 2;

    time_t timer;
    struct tm tm_info;
    strftime(&buf[sz], time_part_size + 1, "%Y.%m.%d %H:%M:%S", localtime_r((time(&timer), &timer), &tm_info) );
    sz += time_part_size;

    buf[sz] = ' ';
    ++sz;

    sprintf(&buf[sz], "[%jd]", pid);
    sz += pid_part_size;

    buf[sz] = '\t';
    ++sz;

    vsnprintf(&buf[sz], isize + 1, fmt, lst2);
    sz += isize;

    buf[sz] = '\n';
    ++sz;

    va_end(lst);
    va_end(lst2);

    assert(sz == sizeof(buf));

    for (size_t i = 0; i < sizeof(buf); ) {
        const ssize_t ret = write(fd, buf, sz);
        if (ret < 0) {
            return;
        }
        assert(ret > 0);
        i += (size_t)ret;
    }

    if (file_fd >= 0) {
        close(file_fd);
    }
}
コード例 #17
0
static BOOL load_head( LOG_HEADER_T* head )
{
    BOOL            create = FALSE;
    fs_handle_type  file;

		sys_mkdir(LOG_DIR, 0700);//make directory..

    if((file = pantech_fopen( LOG_PATH, O_RDONLY, S_IRUSR | S_IWUSR)) != NULL) {
    	if( check_head_valid() == FALSE )
			{
				create = TRUE;
			}
			pantech_fclose(file);
		} else {
			create = TRUE;
		}

    if( create == TRUE )
    {
        if( create_log_file() == FALSE )
        {
            return FALSE;
        }
    }

    file = open_log_file();
    if( file == FS_NULL_HANDLE )
    {
        return FALSE;
    }

    head->first_log_pos_ = get_value( file, FIRST_LOG_POS, 6 ); // FIRST LOG
    head->count_         = get_value( file, LOG_COUNT_POS, 4 ); // 로그수
    head->head_          = get_value( file, HEAD_POS, 4 );      // head
    head->tail_          = get_value( file, TAIL_POS, 4 );      // tail
    head->free_head_     = get_value( file, FREE_HEAD_POS, 4 ); // free head
    if( head->first_log_pos_ == (UINT32)-1 ||
        head->count_         == (UINT32)-1 ||
        head->head_          == (UINT32)-1 ||
        head->tail_          == (UINT32)-1 ||
        head->free_head_     == (UINT32)-1 )
    {
        goto _fail;
    }

    if( get_prev_next( file, head ) == FALSE )
    {
        goto _fail;
    }

    pantech_fclose( file );
    return TRUE;

_fail:
    pantech_fclose( file );
    return FALSE;
}
コード例 #18
0
ファイル: log_linux.c プロジェクト: arungupta2008/FreeDcs
// Checks Either Log file opened or not.
void linux_log_check(){
	if (log_file_fd == STDERR_FILENO) {
		//printf("Log File not opened. Opening Log file \nNote: Here Standard stdout file is opened  \n");
			if(open_log_file(log_file) > STDERR_FILENO){
				log_message(LG_MSG, "linux_logging started");
			}else{
				printf("Failed To open Log file\n");
			}
		}
	}
コード例 #19
0
void log_error(const char* msg){
	open_log_file();

	time_t now_timestamp = time(NULL);
	struct tm* now_time = localtime(&now_timestamp);

	fprintf(log_file, "[ERROR][%d / %d / %d][%d : %d : %d] : %s : %s\n", now_time->tm_mon, now_time->tm_mday, now_time->tm_year + 1990, 
			now_time->tm_hour, now_time->tm_min, now_time->tm_sec,
			strerror(errno), msg);
}
コード例 #20
0
int pantech_logfile_save_log( const char* msg )
{
    fs_handle_type  file;

    file = open_log_file();
    if( file == FS_NULL_HANDLE )
    {
        return -1;
    }

    if( g_head.count_ < MAX_LOG )
    {
        IDX_T new_idx;

        new_idx = add_log( file, &g_head, msg );
        if( new_idx == NULL_IDX ) return FALSE;

        if( set_value( file, LOG_COUNT_POS, g_head.count_, 4 )     == FALSE )      return FALSE;
        if( set_value( file, TAIL_POS, g_head.tail_, 4 )           == FALSE )      return FALSE;
        if( set_value( file, FREE_HEAD_POS, g_head.free_head_, 4 ) == FALSE )      return FALSE;
        if( set_prev_next( file, &g_head, new_idx )                == FALSE )      return FALSE;

        if( g_head.count_ == 1 )
        {
            if( set_value( file, HEAD_POS, g_head.head_, 4 )       == FALSE )      return FALSE;
        }
        else
        {
            if( set_prev_next( file, &g_head, g_head.prev_[ new_idx ] ) == FALSE ) return FALSE;
        }
    }
    else
    {
        IDX_T idx;

        idx                 = g_head.head_;
        g_head.head_        = g_head.next_[ idx ];

        g_head.free_head_   = idx;
        g_head.next_[ idx ] = NULL_IDX;
        g_head.count_--;

        if( add_log( file, &g_head, msg ) != idx ) return FALSE;

        if( set_value( file, HEAD_POS, g_head.head_, 4 )        == FALSE ) return FALSE;
        if( set_value( file, TAIL_POS, g_head.tail_, 4 )        == FALSE ) return FALSE;
        if( set_prev_next( file, &g_head, idx )                 == FALSE ) return FALSE;
        if( set_prev_next( file, &g_head, g_head.prev_[ idx ] ) == FALSE ) return FALSE;
    }

    pantech_fclose( file );

    return 0;
}
コード例 #21
0
ファイル: log.c プロジェクト: azuwis/mpd
static void
log_init_file(const char *path, unsigned line)
{
	out_filename = path;
	out_fd = open_log_file();
	if (out_fd < 0)
		g_error("problem opening log file \"%s\" (config line %u) for "
			"writing\n", path, line);

	g_log_set_default_handler(file_log_func, NULL);
}
コード例 #22
0
ファイル: init_and_destroy.c プロジェクト: Zhanyin/taomee
/*
 * @brief 初始化,包括设置本次循环时间,改变工作目录,加载日志文件(每次循环都加载,以便修改配置文件后不需要重启),打开日志
 * @prame 执行路径 argv[0]
 */
int initiate(char *path)
{
	//获取程序运行时路径前缀,改变工作目录,找到配置文件、打开错误文件.他们与可执行程序位于同一目录
	if (change_working_path(path) == -1)
		return -1;
	//在当前位置打开日志记录文件
	if (open_log_file() == -1) {
		fprintf(stderr, "open log file failed!\n");
		return -1;
	}
	return 0;
}
コード例 #23
0
ファイル: log.cpp プロジェクト: songweibeijing/dirInfoMonitor
void init_persist_log(void)
{
    int ret = 0;
    int i = 0;
    pthread_t p_async_writer;

    log_fd_invalid = 1;
    ret = parser_log_configure();
    if (ret < 0)
    {
        printf("parser_log_configure failed\n");
        /* set the default value */
        level_log = LOG_NOTICE;
    }
    if (open_log_file(PERSIST_LOG) < 0)
    {
        printf("open log file failed\n");
        return; //just return, logdaemon without log
    }

    g_index = 0;
    while (i < 2)
    {
        pthread_mutex_init(&g_locks[i], NULL);
        g_buffer[i] = (char *)malloc(MAX_BUFFER_SIZE);
        if (NULL == g_buffer[i])
        {
            goto failed;
        }
        memset(g_buffer[i], 0, MAX_BUFFER_SIZE);
        g_buffer_pos[i] = 0;
        i++;
    }

    if (pthread_create(&p_async_writer, NULL, async_write, NULL) < 0)
    {
        goto failed;
    }

    return;

failed:
    if (g_buffer[0] != NULL)
    {
        free(g_buffer[0]);
    }
    if (g_buffer[1] != NULL)
    {
        free(g_buffer[1]);
    }
    log_fd_invalid = 1;
    return; //logdaemon without log
}
コード例 #24
0
ファイル: logger.c プロジェクト: caivega/minisphere
static duk_ret_t
js_new_Logger(duk_context* ctx)
{
	const char* filename = duk_get_string(ctx, 0);

	char* path = get_asset_path(filename, "logs", true);
	logger_t* logger = open_log_file(path);
	free(path);
	if (logger == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "OpenLog(): Failed to open file for logging '%s'", filename);
	duk_push_sphere_obj(ctx, "Logger", logger);
	return 1;
}
コード例 #25
0
ファイル: udploggerc.c プロジェクト: rbroemeling/udplogger
void inline log_packet_hook(struct sockaddr_in *sender, char *line)
{
	static time_t current_timestamp = 0;
	static struct tm current_time;
	static char current_time_str[TIME_STRING_BUFFER_SIZE];
	int i;
	static char new_log_destination_path[TIME_STRING_BUFFER_SIZE];

	/* Update our timestamp string (if necessary). */
	if ((! current_timestamp) || (current_timestamp != time(NULL)))
	{
		current_timestamp = time(NULL);
		if (current_timestamp == (time_t)-1)
		{
			perror("udploggerc.c time()");
			return;
		}
		if (localtime_r(&current_timestamp, &current_time) == NULL)
		{
			perror("udploggerc.c localtime_r()");
			return;
		}
		strftime(current_time_str, TIME_STRING_BUFFER_SIZE, "[%Y-%m-%d %H:%M:%S]", &current_time);
		current_time_str[TIME_STRING_BUFFER_SIZE - 1] = '\0';

		/* Update our log file destination path (if necessary). */
		if (udploggerc_conf.log_destination_format != NULL)
		{
			strftime(new_log_destination_path, TIME_STRING_BUFFER_SIZE, udploggerc_conf.log_destination_format, &current_time);
			new_log_destination_path[TIME_STRING_BUFFER_SIZE - 1] = '\0';
			if (strncmp(new_log_destination_path, udploggerc_conf.log_destination_path, TIME_STRING_BUFFER_SIZE))
			{
				open_log_file(new_log_destination_path);
			}
		}
	}

	/* Format the log line for output. */
	if (udploggerc_conf.delimiter_character != DELIMITER_CHARACTER)
	{
		for (i = 0; i < strnlen(line, PACKET_MAXIMUM_SIZE); i++)
		{
			if (line[i] == DELIMITER_CHARACTER)
			{
				line[i] = udploggerc_conf.delimiter_character;
			}
		}
	}

	fprintf(udploggerc_conf.log_destination, "%s%c[%s:%hu]%c%s\n", current_time_str, udploggerc_conf.delimiter_character, inet_ntoa(sender->sin_addr), ntohs(sender->sin_port), udploggerc_conf.delimiter_character, line);
}
コード例 #26
0
ファイル: sprtf.c プロジェクト: geoffmcl/tidy-test
static void oi( char * psin )
{
    int len, w;
    char * ps = psin;
    if (!ps)
        return;

   len = (int)strlen(ps);
   if (len) {

      if( outfile == 0 ) {
         open_log_file();
      }
      if( VFP(outfile) ) {
          char *tb;
          if (addsysdate) {
              tb = GetNxtBuf();
              len = sprintf( tb, "%s - %s", get_date_time_stg(), ps );
              ps = tb;
          } else if( addsystime ) {
              tb = GetNxtBuf();
              len = sprintf( tb, "%s - %s", get_time_stg(), ps );
              ps = tb;
          }

         w = (int)fwrite( ps, 1, len, outfile );
         if( w != len ) {
            fclose(outfile);
            outfile = (FILE *)-1;
            sprtf("WARNING: Failed write to log file [%s] ...\n", logfile);
            exit(1);
         } else if (addflush) {
            fflush( outfile );
         }
      }

      if( addstdout ) {
         fwrite( ps, 1, len, stderr );  /* 20170917 - Switch to using 'stderr' in place of 'stdout' */
      }
#ifdef ADD_LISTVIEW
       if (add2listview) {
           LVInsertItem(ps);
       } 
#endif /* ADD_LISTVIEW */
#ifdef ADD_SCREENOUT
       if (add2screen) {
          Add_String(ps);    /* add string to screen list */
       }
#endif /* #ifdef ADD_SCREENOUT */
   }
}
コード例 #27
0
ファイル: logging.c プロジェクト: SuprDewd/NineToFive
void log_event(const char *log_name, time_t time, const char *event) {
    ensure_log_file_exists(log_name);

    FILE *log = open_log_file(log_name, "a");

    char *time_str = to_utc_str(time);

    if (fprintf(log, "%s %s\n", time_str, event) < 0) {
        fatal("could not write to log file: %s", strerror(errno));
    }

    fclose(log);
    free(time_str);
}
コード例 #28
0
ファイル: log.c プロジェクト: Acidburn0zzz/mpd
static bool
log_init_file(const char *path, unsigned line, GError **error_r)
{
	out_filename = path;
	out_fd = open_log_file();
	if (out_fd < 0) {
		g_set_error(error_r, log_quark(), errno,
			    "failed to open log file \"%s\" (config line %u): %s",
			    path, line, g_strerror(errno));
		return false;
	}

	g_log_set_default_handler(file_log_func, NULL);
	return true;
}
コード例 #29
0
ファイル: dpx.c プロジェクト: ufo5260987423/yandytex-src
void ensure_pdf_open(void)
{
  if (output_file_name == 0)
  {
    if (job_name == 0)
      open_log_file();

    pack_job_name(".pdf");

    while (!b_open_out(pdf_file))
      prompt_file_name("file name for output", ".pdf");

    output_file_name = b_make_name_string(pdf_file);
  }
}
コード例 #30
0
ファイル: sprtf.c プロジェクト: geoffmcl/tidy-test
void   set_log_file( char * nf, int open )
{
   if (logfile[0] == 0)
      strcpy(logfile,def_log);
   if ( nf && *nf && strcmpi(nf,logfile) ) {
      close_log_file(); /* remove any previous */
      strcpy(logfile,nf); /* set new name */
      if (strcmp(logfile,"none") == 0) { /* if equal 'none' */
          outfile = (FILE *)-1; /* disable the log file */
      } else if (open) {
          open_log_file();  /* and open it ... anything previous written is 'lost' */
      } else
          outfile = 0; /* else set 0 to open on first write */
   }
}