Skip to content

Commit

Permalink
Loggerに時間範囲のオプションを追加 (#54)
Browse files Browse the repository at this point in the history
* Add the time range variables to Logger to control the logging information.

* Add the time range variables to Logger to control the logging information.

* Loggerの条件漏れを追加
  • Loading branch information
hidehisaakiyama authored Mar 15, 2023
1 parent 5f30d69 commit 6a21ae9
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 20 deletions.
89 changes: 69 additions & 20 deletions rcsc/common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ Logger dlog;
Logger::Logger()
: M_time( nullptr ),
M_fout( nullptr ),
M_flags( 0 )
M_flags( 0 ),
M_start_time( -1 ),
M_end_time( 99999999 )
{
g_str.reserve( 8192 * 4 );
std::strcpy( g_buffer, "" );
Expand Down Expand Up @@ -104,6 +106,15 @@ Logger::setLogFlag( const GameTime * time,
}
}

/*-------------------------------------------------------------------*/
void
Logger::setTimeRange( const int start_time,
const int end_time )
{
M_start_time = start_time;
M_end_time = end_time;
}

/*-------------------------------------------------------------------*/
/*!
Expand Down Expand Up @@ -196,7 +207,9 @@ Logger::addText( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
va_list argp;
va_start( argp, msg );
Expand Down Expand Up @@ -231,7 +244,9 @@ Logger::addPoint( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d p %.4f %.4f ",
Expand Down Expand Up @@ -260,7 +275,9 @@ Logger::addPoint( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d p %.4f %.4f #%02x%02x%02x",
Expand Down Expand Up @@ -288,7 +305,9 @@ Logger::addLine( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d l %.4f %.4f %.4f %.4f ",
Expand Down Expand Up @@ -319,7 +338,9 @@ Logger::addLine( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d l %.4f %.4f %.4f %.4f #%02x%02x%02x",
Expand Down Expand Up @@ -348,7 +369,9 @@ Logger::addArc( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d a %.4f %.4f %.4f %.4f %.4f ",
Expand Down Expand Up @@ -383,7 +406,9 @@ Logger::addArc( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d a %.4f %.4f %.4f %.4f %.4f #%02x%02x%02x",
Expand Down Expand Up @@ -411,7 +436,9 @@ Logger::addCircle( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f ",
Expand Down Expand Up @@ -443,7 +470,9 @@ Logger::addCircle( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f #%02x%02x%02x",
Expand Down Expand Up @@ -475,7 +504,9 @@ Logger::addTriangle( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f %.4f %.4f %.4f ",
Expand Down Expand Up @@ -510,7 +541,9 @@ Logger::addTriangle( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f %.4f %.4f %.4f #%02x%02x%02x",
Expand Down Expand Up @@ -540,7 +573,9 @@ Logger::addRect( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f %.4f ",
Expand Down Expand Up @@ -573,7 +608,9 @@ Logger::addRect( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f %.4f #%02x%02x%02x",
Expand Down Expand Up @@ -605,7 +642,9 @@ Logger::addSector( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f %.4f %.4f %.4f ",
Expand Down Expand Up @@ -641,7 +680,9 @@ Logger::addSector( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
snprintf( msg, 128, "%ld,%ld %d %c %.4f %.4f %.4f %.4f %.4f %.4f #%02x%02x%02x",
Expand Down Expand Up @@ -669,7 +710,9 @@ Logger::addSector( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
double span_angle = ( sector.angleLeftStart().isLeftOf( sector.angleRightEnd() )
Expand Down Expand Up @@ -704,7 +747,9 @@ Logger::addSector( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char msg[128];
double span_angle = ( sector.angleLeftStart().isLeftOf( sector.angleRightEnd() )
Expand Down Expand Up @@ -737,7 +782,9 @@ Logger::addMessage( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char header[128];
snprintf( header, 128, "%ld,%ld %d m %.4f %.4f ",
Expand Down Expand Up @@ -772,7 +819,9 @@ Logger::addMessage( const std::int32_t level,
{
if ( M_fout
&& M_time
&& ( level & M_flags ) )
&& ( level & M_flags )
&& M_start_time <= M_time->cycle()
&& M_time->cycle() <= M_end_time )
{
char header[128];
snprintf( header, 128, "%ld,%ld %d m %.4f %.4f ",
Expand Down
11 changes: 11 additions & 0 deletions rcsc/common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class Logger {
//! log level flag
std::int32_t M_flags;

int M_start_time;
int M_end_time;

public:
/*!
\brief allocate message buffer memory
Expand All @@ -176,6 +179,14 @@ class Logger {
const std::int32_t level,
const bool on = true );

/*!
\brief set the range of the recorded game time
\param start_time lower value
\param end_time higher value
*/
void setTimeRange( const int start_time,
const int end_time );

/*!
\brief check if the level is enabled
\param level checked log level
Expand Down
2 changes: 2 additions & 0 deletions rcsc/player/player_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,8 @@ PlayerAgent::Impl::setDebugFlags()
return;
}

dlog.setTimeRange( c.debugStartTime(), c.debugEndTime() );

dlog.setLogFlag( &current_time_, Logger::SYSTEM, c.debugSystem() );
dlog.setLogFlag( &current_time_, Logger::SENSOR, c.debugSensor() );
dlog.setLogFlag( &current_time_, Logger::WORLD, c.debugWorld() );
Expand Down
6 changes: 6 additions & 0 deletions rcsc/player/player_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ PlayerConfig::setDefaultParam()
//
// debug logging
//
M_debug_start_time = -1;
M_debug_end_time = 99999999;

M_debug_log_ext = ".log";

M_debug_system = false;
Expand Down Expand Up @@ -239,6 +242,9 @@ PlayerConfig::createParamMap()
( "offline_log_ext", "", &M_offline_log_ext )
( "offline_client_number", "", &M_offline_client_number )

( "debug_start_time", "", &M_debug_start_time )
( "debug_end_time", "", &M_debug_end_time )

( "debug_log_ext", "", &M_debug_log_ext )

( "debug_system", "", BoolSwitch( &M_debug_system ) )
Expand Down
15 changes: 15 additions & 0 deletions rcsc/player/player_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class PlayerConfig {
// debug logging
//

int M_debug_start_time; //!< the start time for recording the debug log
int M_debug_end_time; //!< the end time for recording the debug log

std::string M_debug_log_ext; //!< the extension string of debug log file

bool M_debug_system; //!< debug level flag
Expand Down Expand Up @@ -469,6 +472,18 @@ class PlayerConfig {
// debug logging
//

/*!
\brief get the start time for receoding the debug log
\return the start time for receoding the debug log
*/
int debugStartTime() const { return M_debug_start_time; }

/*!
\brief get the end time for receoding the debug log
\return the end time for receoding the debug log
*/
int debugEndTime() const { return M_debug_end_time; }

/*!
\brief get the debug log file extention string.
\return the debug log file extention string.
Expand Down

0 comments on commit 6a21ae9

Please sign in to comment.