Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion ACE/ace/ACE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,7 @@ ACE::timestamp (ACE_TCHAR date_and_time[],
}

/// Returns the given timestamp in the form
/// "hour:minute:second:microsecond." The month, day, and year are
/// "hour:minute:second.microsecond." The month, day, and year are
/// also stored in the beginning of the date_and_time array
/// using ISO-8601 format.
/// 012345678901234567890123456
Expand Down Expand Up @@ -2430,6 +2430,39 @@ ACE::timestamp (const ACE_Time_Value& time_value,
return &date_and_time[10 + (return_pointer_to_first_digit != 0)];
}

/// Returns the given duration in the form
/// "hour:minute:second.microsecond."
/// 0123456789012345
/// 12:56:00.123456<nul>
ACE_TCHAR *
ACE::duration (const ACE_Time_Value& duration_value,
ACE_TCHAR duration[],
size_t duration_len)
{
//ACE_TRACE ("ACE::duration");

// This magic number is from the formatting statement
// farther down this routine.
if (duration_len < 16)
{
errno = EINVAL;
return 0;
}

time_t secs = duration_value.sec ();
struct tm tms;
ACE_OS::gmtime_r (&secs, &tms);
ACE_OS::snprintf (duration,
duration_len,
ACE_TEXT ("%2.2d:%2.2d:%2.2d.%06ld"),
tms.tm_hour,
tms.tm_min,
tms.tm_sec,
static_cast<long> (duration_value.usec ()));
duration[duration_len - 1] = '\0';
return &duration[0];
}

/// This function rounds the request to a multiple of the page size.
size_t
ACE::round_to_pagesize (size_t len)
Expand Down
21 changes: 20 additions & 1 deletion ACE/ace/ACE.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ namespace ACE
* Translate the given timestamp to ISO-8601 format.
*
* @param time_value ACE_Time_Value to format. This is assumed to be
* an absolute time value.
* an absolute time value. Passing ACE_Time_Value::zero
uses gettimeofday().
* @param date_and_time Array to hold the timestamp.
* @param time_len Size of @a date_and_time in ACE_TCHARs.
* Must be greater than or equal to 27.
Expand All @@ -498,6 +499,24 @@ namespace ACE
size_t time_len,
bool return_pointer_to_first_digit = false);

/**
* Translate the given duration to ISO-8601 format. Note that the current
* implementation cannot handle durations larger or equal to 24 hours.
*
* @param duration_value ACE_Time_Value to format. This is assumed to be
* a time period.
* @param duration Array to hold the duration.
* @param duration_len Size of @a duration in ACE_TCHARs.
* Must be greater than or equal to 16.
*
* @retval 0 if unsuccessful, with errno set. If @a duration_len is less than
* 16 errno will be EINVAL.
* @retval If successful, pointer to beginning of @a duration.
*/
extern ACE_Export ACE_TCHAR *duration (const ACE_Time_Value& duration_value,
ACE_TCHAR duration[],
size_t duration_len);

/**
* Translate the current time to ISO-8601 timestamp format.
*
Expand Down
39 changes: 39 additions & 0 deletions ACE/ace/Log_Msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,37 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str,
break;
}

case 'Y': // Format the duration in hour:minute:sec.usec format.
// Note that this currently overflows if the provided
// duration is larger or equal to 24 hours.
{
ACE_TCHAR duration[16];
ACE_OS::strcpy (fp, ACE_TEXT_PRIs);
// Did we find the flag indicating a time value argument
if (format[1] == ACE_TEXT('#'))
{
ACE_Time_Value* duration_value = va_arg (argp, ACE_Time_Value*);
if (can_check)
this_len = ACE_OS::snprintf
(bp, bspace, format,
ACE::duration (*duration_value,
duration,
sizeof duration / sizeof (ACE_TCHAR)));
else
this_len = ACE_OS::sprintf
(bp, format, ACE::duration (*duration_value,
duration,
sizeof duration / sizeof (ACE_TCHAR)));
}
else
{
ACE_OS::fprintf (stderr,
"error: %%Y requires # modifier\n");
}
ACE_UPDATE_COUNT (bspace, this_len);
break;
}

case 't': // Format thread id.
#if defined (ACE_WIN32)
ACE_OS::strcpy (fp, ACE_TEXT ("u"));
Expand Down Expand Up @@ -2415,6 +2446,14 @@ bool ACE_Log_Formatter::process_conversion ()
this->bp_ += len;
}
break;
// %Y with # in the conversion spec takes an arg (ACE_Time_Value*)
case 'Y':
ACE_OS::strcpy (this->fp_, "s");
if (ACE_OS::memchr (this->fmt_out_, '#', this->fp_ - this->fmt_out_))
return false;
ACE_OS::fprintf (stderr,
"error: %%Y requires # modifier\n");
break;

case '{':
this->logger_->inc ();
Expand Down
6 changes: 5 additions & 1 deletion ACE/ace/Log_Msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class ACE_Export ACE_Log_Msg
* - 'S': print out the appropriate signal message corresponding
* to var-argument, e.g., as done by strsignal()
* - 's': prints a ACE_TCHAR* character string (also see C and W)
* - 'T': print timestamp in hour:minute:sec:usec format (plain option,
* - 'T': print timestamp in hour:minute:sec.usec format (plain option,
* i.e. without any flags, prints system supplied timestamp;
* with '#' flag added expects ACE_Time_Value* in argument list)
* - 'D': print timestamp as Weekday Month day year hour:minute:sec.usec
Expand All @@ -555,6 +555,10 @@ class ACE_Export ACE_Log_Msg
* - 'W': prints a wchar_t* character string (also see C and s)
* - 'x': print as a hex number
* - 'X': print as a hex number
* - 'Y': print duration in hour:minute:sec.usec format (plain option,
* i.e. without any flags, is currently unspecified;
* with '#' flag added expects ACE_Time_Value* in argument list)
* Note that durations >= 24 hours will currently overflow
* - 'z': print an ACE_OS::WChar character
* - 'Z': print an ACE_OS::WChar character string
* - ':': print a time_t value as an integral number
Expand Down
Loading