diff options
author | Chris Wilson <chris+github@qwirx.com> | 2013-08-21 23:44:12 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2013-08-21 23:44:12 +0000 |
commit | 410c85a13d5812efeadb13e3ffa82b9629331100 (patch) | |
tree | cdd1d687366ac3f3f912749c7c0d6a8219ff8efa | |
parent | bf72ccefc5afb373582374e2a71a7287b92e8e3b (diff) |
Add a ToString() method on protocol objects, to help with debugging them.
-rwxr-xr-x | lib/server/makeprotocol.pl.in | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in index 27a82959..ddf0509b 100755 --- a/lib/server/makeprotocol.pl.in +++ b/lib/server/makeprotocol.pl.in @@ -342,6 +342,7 @@ __E print H "\tvirtual void LogSysLog(const char *Action) const;\n"; print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n"; + print H "\tvirtual std::string ToString() const;\n"; # write member variables and setup for cpp file my @def_constructor_list; @@ -467,31 +468,34 @@ __E my ($log) = make_log_strings_framework($cmd); print CPP <<__E; -void $cmd_class\::LogSysLog(const char *Action) const +std::string $cmd_class\::ToString() const { + std::ostringstream oss; try { - BOX_TRACE($log); + oss << $log; } catch(std::exception &e) { - BOX_WARNING("Failed to log command: " << Action << ": " << - e.what()); + oss << "Failed to log command: " << e.what(); } + return oss.str(); } -void $cmd_class\::LogFile(const char *Action, FILE *File) const +void $cmd_class\::LogSysLog(const char *Action) const { - std::ostringstream oss; try { - oss << $log; + BOX_TRACE(Action << " " << $log); } catch(std::exception &e) { - oss << "Failed to log command: " << Action << ": " << - e.what(); + BOX_WARNING("Failed to log command: " << Action << ": " << + e.what()); } - ::fprintf(File, "%s\\n", oss.str().c_str()); +} +void $cmd_class\::LogFile(const char *Action, FILE *File) const +{ + ::fprintf(File, "%s %s\\n", Action, ToString().c_str()); ::fflush(File); } __E @@ -1184,7 +1188,7 @@ sub make_log_strings_framework } } - my $log_cmd = "Action << \" $cmd(\" "; + my $log_cmd = '"'.$cmd.'(" '; foreach my $arg (@args) { $arg = "<< $arg "; |