Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol buffers logging

In our business, we require to log every request/response which coming to our server. At this time being, we are using xml as standard implementation. Log files are used if we need to debug/trace some error.

I am kind of curious if we switch to protocol buffers, since it is binary, what will be the best way to log request/response to file?

For example:

FileOutputStream output = new FileOutputStream("\\files\log.txt");
request.build().writeTo(outout);

For anyone who has used protocol buffers in your application, how do you log your request/response, just in case we need it for debugging purpose?

like image 888
user373307 Avatar asked Jun 23 '10 13:06

user373307


2 Answers

TL;DR: write debugging logs in text, write long-term logs in binary.

There are at least two ways you can do this logging (and maybe, in fact, you should do both):

  1. Writing your logs in text format. This is good for debugging and quickly checking for problems with your eyes.
  2. Writing your logs in binary format - this will make future analysis much quicker since you can load the data using same protocol buffers code and do all kinds of things on them.

Quite honestly, this is more or less the way this is done at the place this technology came from.

like image 109
sgzmd Avatar answered Oct 21 '22 20:10

sgzmd


We use the ShortDebugString() method on the C++ object to write down a human-readable version of all incoming and outgoing messages to a text-file. ShortDebugString() returns a one-line version of the same string returned by the toString() method in Java. Not sure how easy it is to accomplish the same thing in Java.

like image 21
JesperE Avatar answered Oct 21 '22 19:10

JesperE