Replaced the filename for packet log file in the UserConfig with a

flag to enable/disable this debug output in the file STDOUT.packets
(where stdout is the final set at startup).
This commit is contained in:
hiker 2016-03-03 17:10:18 +11:00
parent 4947881d10
commit ab641b0dad
5 changed files with 22 additions and 11 deletions

View File

@ -593,9 +593,9 @@ namespace UserConfigParams
"stun.voxgratia.org",
"stun.xten.com") );
PARAM_PREFIX StringUserConfigParam m_packets_log_filename
PARAM_DEFAULT( StringUserConfigParam("packets_log.txt", "packets_log_filename",
"Where to log received and sent packets.") );
PARAM_PREFIX BoolUserConfigParam m_log_packets
PARAM_DEFAULT( BoolUserConfigParam(false, "log-network-packets",
"If all network packets should be logged") );
// ---- Graphic Quality
PARAM_PREFIX GroupUserConfigParam m_graphics_quality

View File

@ -146,6 +146,9 @@ public:
return fileExists(std::string(prefix) + path);
}
// ------------------------------------------------------------------------
/** Returns the name of the stdout file for log messages. */
static const std::string& getStdoutName() { return m_stdout_filename; }
// ------------------------------------------------------------------------
void listFiles (std::set<std::string>& result,
const std::string& dir,
bool make_full_path=false) const;

View File

@ -172,10 +172,10 @@ void Network::broadcastPacket(NetworkString *data, bool reliable)
void Network::openLog()
{
m_log_file.setAtomic(NULL);
if (UserConfigParams::m_packets_log_filename.toString() != "")
if (UserConfigParams::m_log_packets)
{
std::string s = file_manager
->getUserConfigFile(UserConfigParams::m_packets_log_filename);
->getUserConfigFile(FileManager::getStdoutName()+".packet");
m_log_file.setAtomic(fopen(s.c_str(), "w+"));
}
if (!m_log_file.getData())
@ -198,8 +198,10 @@ void Network::logPacket(const BareNetworkString &ns, bool incoming)
m_log_file.lock();
fprintf(m_log_file.getData(), "[%d\t] %s ",
(int)(StkTime::getRealTime()), arrow);
fprintf(m_log_file.getData(), ns.getLogMessage().c_str());
// Indentation for all lines after the first, so that the dump
// is nicely aligned.
std::string indent(" ");
fprintf(m_log_file.getData(), ns.getLogMessage(indent).c_str());
m_log_file.unlock();
} // logPacket
// ----------------------------------------------------------------------------

View File

@ -64,7 +64,7 @@ void NetworkString::unitTesting()
for(unsigned int i=0; i<28; i++)
slog.addUInt8(i);
std::string log = slog.getLogMessage();
assert(log=="0x000 | 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f | ................\n"
assert(log=="0x000 | 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f | ................\n"
"0x010 | 10 11 12 13 14 15 16 17 18 19 1a 1b | ............\n");
} // unitTesting
@ -128,7 +128,7 @@ int BareNetworkString::decodeStringW(int pos, irr::core::stringw *out) const
* to stdout or via the Log mechanism. Format
* 0000 : 1234 5678 9abc ... ASCII-
*/
std::string BareNetworkString::getLogMessage() const
std::string BareNetworkString::getLogMessage(const std::string &indent) const
{
std::ostringstream oss;
for(unsigned int line=0; line<m_buffer.size(); line+=16)
@ -154,12 +154,18 @@ std::string BareNetworkString::getLogMessage() const
for(unsigned int i=line; i<upper_limit; i++)
{
uint8_t c = m_buffer[i];
if(isprint(c) && c!=0x09) // Don't print tabs
// Don't print tabs, and characters >=128, which are often shown
// as more than one character.
if(isprint(c) && c!=0x09 && c<=0x80)
oss << char(c);
else
oss << '.';
} // for i
oss << "\n";
// If it's not the last line, add the indentation in front
// of the next line
if(line+16<m_buffer.size())
oss << indent;
} // for line
return oss.str();

View File

@ -139,7 +139,7 @@ public:
BareNetworkString& encodeString(const irr::core::stringw &value);
int decodeString(int n, std::string *out) const;
int decodeStringW(int n, irr::core::stringw *out) const;
std::string getLogMessage() const;
std::string getLogMessage(const std::string &indent="") const;
// ------------------------------------------------------------------------
/** Returns a byte pointer to the content of the network string. */
char* getData() { return (char*)(m_buffer.data()); };