예제 #1
0
파일: log.c 프로젝트: jokva/ert
/**
   If dup_stream != NULL the message (without the date/time header) is duplicated on this stream.
*/
void log_add_message(log_type *logh, int message_level , FILE * dup_stream , char* message, bool free_message) {
    if (log_include_message(logh,message_level)) {

        if (logh->stream == NULL)
            util_abort("%s: logh->stream == NULL - must call log_reset_filename() first \n",__func__);

#ifdef HAVE_PTHREAD
        pthread_mutex_lock( &logh->mutex );
#endif
        {
            struct tm time_fields;
            time_t    epoch_time;

            time(&epoch_time);
            util_localtime(&epoch_time , &time_fields);

            if (message != NULL)
                fprintf(logh->stream,"%02d/%02d - %02d:%02d:%02d  %s\n",time_fields.tm_mday, time_fields.tm_mon + 1, time_fields.tm_hour , time_fields.tm_min , time_fields.tm_sec , message);
            else
                fprintf(logh->stream,"%02d/%02d - %02d:%02d:%02d   \n",time_fields.tm_mday, time_fields.tm_mon + 1, time_fields.tm_hour , time_fields.tm_min , time_fields.tm_sec);

            /** We duplicate the message to the stream 'dup_stream'. */
            if ((dup_stream != NULL) && (message != NULL))
                fprintf(dup_stream , "%s\n", message);

            log_sync( logh );
        }
#ifdef HAVE_PTHREAD
        pthread_mutex_unlock( &logh->mutex );
#endif
        if (free_message)
            free( message );
    }
}
예제 #2
0
uint32_t util_date_number(time_t time)
{
    struct tm now_tm;
    util_localtime(&time, &now_tm);
    return (uint32_t)(now_tm.tm_year + 1900) * 10000
        + (uint32_t)(now_tm.tm_mon + 1) * 100
        + (uint32_t)now_tm.tm_mday;
}
예제 #3
0
void util_timestamp(struct timeval* time, char* stamp, size_t sz)
{
    struct tm now_tm;
    util_localtime((time_t*)&time->tv_sec, &now_tm);
    snprintf(stamp, sz, "[%d-%02d-%02d %02d:%02d:%02d:%06d]",
        now_tm.tm_year + 1900,
        now_tm.tm_mon + 1,
        now_tm.tm_mday,
        now_tm.tm_hour,
        now_tm.tm_min,
        now_tm.tm_sec,
        (uint32_t)time->tv_usec);
}
예제 #4
0
파일: output.c 프로젝트: tomaszkapela/nvml
/*
 * out_get_time_str -- returns time in human readable format
 */
const char *
out_get_time_str(time_t time)
{
	static char str_buff[STR_MAX] = {0, };
	struct tm *tm = util_localtime(&time);

	if (tm) {
		strftime(str_buff, STR_MAX, TIME_STR_FMT, tm);
	} else {
		int ret = snprintf(str_buff, STR_MAX, "unknown");
		if (ret < 0 || ret >= STR_MAX)
			return "";
	}

	return str_buff;
}
예제 #5
0
파일: ecl_sum.c 프로젝트: flikka/ert
static void __ecl_sum_fprintf_line( const ecl_sum_type * ecl_sum , FILE * stream , int internal_index , const bool_vector_type * has_var , const int_vector_type * var_index , char * date_string , const ecl_sum_fmt_type * fmt) {
  fprintf(stream , fmt->days_fmt , ecl_sum_iget_sim_days(ecl_sum , internal_index));
  fprintf(stream , "%s", fmt->sep );

  {
    struct tm ts;
    time_t sim_time = ecl_sum_iget_sim_time(ecl_sum , internal_index );
    util_localtime( &sim_time , &ts);
    strftime( date_string , DATE_STRING_LENGTH - 1 , fmt->date_fmt , &ts);
    fprintf(stream , "%s", date_string );
  }

  {
    int ivar;
    for (ivar = 0; ivar < int_vector_size( var_index ); ivar++) {
      if (bool_vector_iget( has_var , ivar )) {
        fprintf(stream , "%s", fmt->sep);
        fprintf(stream , fmt->value_fmt , ecl_sum_iget(ecl_sum , internal_index, int_vector_iget( var_index , ivar )));
      }
    }
  }

  fprintf(stream , "%s", fmt->newline);
}