From 6a21ae9d27e65c35a7172cec73cd01c79607c46d Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama <522630+hidehisaakiyama@users.noreply.github.com> Date: Wed, 15 Mar 2023 19:51:33 +0900 Subject: [PATCH] =?UTF-8?q?Logger=E3=81=AB=E6=99=82=E9=96=93=E7=AF=84?= =?UTF-8?q?=E5=9B=B2=E3=81=AE=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=20(#54)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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の条件漏れを追加 --- rcsc/common/logger.cpp | 89 +++++++++++++++++++++++++++-------- rcsc/common/logger.h | 11 +++++ rcsc/player/player_agent.cpp | 2 + rcsc/player/player_config.cpp | 6 +++ rcsc/player/player_config.h | 15 ++++++ 5 files changed, 103 insertions(+), 20 deletions(-) diff --git a/rcsc/common/logger.cpp b/rcsc/common/logger.cpp index 80c84e4..236214e 100644 --- a/rcsc/common/logger.cpp +++ b/rcsc/common/logger.cpp @@ -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, "" ); @@ -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; +} + /*-------------------------------------------------------------------*/ /*! @@ -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 ); @@ -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 ", @@ -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", @@ -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 ", @@ -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", @@ -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 ", @@ -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", @@ -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 ", @@ -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", @@ -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 ", @@ -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", @@ -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 ", @@ -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", @@ -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 ", @@ -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", @@ -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() ) @@ -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() ) @@ -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 ", @@ -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 ", diff --git a/rcsc/common/logger.h b/rcsc/common/logger.h index ee9272e..c03a01a 100644 --- a/rcsc/common/logger.h +++ b/rcsc/common/logger.h @@ -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 @@ -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 diff --git a/rcsc/player/player_agent.cpp b/rcsc/player/player_agent.cpp index 6c26842..4510f42 100644 --- a/rcsc/player/player_agent.cpp +++ b/rcsc/player/player_agent.cpp @@ -1408,6 +1408,8 @@ PlayerAgent::Impl::setDebugFlags() return; } + dlog.setTimeRange( c.debugStartTime(), c.debugEndTime() ); + dlog.setLogFlag( ¤t_time_, Logger::SYSTEM, c.debugSystem() ); dlog.setLogFlag( ¤t_time_, Logger::SENSOR, c.debugSensor() ); dlog.setLogFlag( ¤t_time_, Logger::WORLD, c.debugWorld() ); diff --git a/rcsc/player/player_config.cpp b/rcsc/player/player_config.cpp index b8b2113..d0c8f2b 100644 --- a/rcsc/player/player_config.cpp +++ b/rcsc/player/player_config.cpp @@ -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; @@ -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 ) ) diff --git a/rcsc/player/player_config.h b/rcsc/player/player_config.h index dcf7dc8..d571da3 100644 --- a/rcsc/player/player_config.h +++ b/rcsc/player/player_config.h @@ -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 @@ -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.