<p>I'm designing an application which includes the need to log all incoming messages I receive from a Telnet connection. The text is largely plain though can include ANSI tags that provide text colour and formatting (16 colours, bold, underline, etc).</p>

<p>I'm would like to format my logs to store the text with formatting, date/time and potentially other meta data later. My first thoughts was all XML but this could impact my ability to write a fast search tool later. My current idea is Date/Time + text in one file with meta-data stored in another XML file, referenced by line number.</p>

<p>Is this a good solution? Also, where and how should I store the formatting commands? The original ANSI tags would disrupt the plain but having them in two different files might be awkward.</p>

<p>Additional: Thanks to some answers so far, though I should mention that most of the time the messages will be person to person communications rather than system messages. A more primitive IRC of sorts. Its up to my user to decide later (by adding meta data) which messages were important. This is the raw on the record log that filtered or edited logs might derive from.</p>

[{'answer_id': 50710, 'author': 'Craig', 'author_id': 2894, 'author_profile': 'https://Stackoverflow.com/users/2894', 'pm_score': 0, 'selected': False, 'text': "<p>If you are catpuring logging information for future searching and anaylsis perhaps a database would be a better answer.  </p>\n\n<p>As for your solution.  Flat files do not scale well at all where as a database scale much better.  I wouldn't split the files either, that just compounds the scalability issue.  If you have to use a flat file I would probably try keeping the meta data in a csv (less over head) and the data in a series of files indexed by the csv file.  That way all the data doesn't impact your index file.  Just my thoughts.</p>\n"}, {'answer_id': 50717, 'author': 'Rob Wells', 'author_id': 2974, 'author_profile': 'https://Stackoverflow.com/users/2974', 'pm_score': 1, 'selected': False, 'text': "<p>G'day,</p>\n\n<p>Definitely do the logging in flat file and add munge scripts to turn it into XMl later.</p>\n\n<p>First suggestion would be to make sure that all date/time strings are in ISO 8601 format, namely YYYY-MM-DD hh:mm:ss.</p>\n\n<p>Second is to make your categories, e.g. exception, fatal, error, warning, info, etc. really stand out in your logs.</p>\n\n<p>Then aybe look at some of the vim syntax files and create a new syntax for your log format so that important log entries really stand out.</p>\n\n<p>It's not really that hard to take one of the standard syntax files and modify it to handle your log strings.</p>\n\n<p>HTH.</p>\n\n<p>cheers,</p>\n\n<p>Rob</p>\n"}, {'answer_id': 50793, 'author': 'Yes - that Jake.', 'author_id': 5287, 'author_profile': 'https://Stackoverflow.com/users/5287', 'pm_score': 2, 'selected': False, 'text': '<p>My first suggestion would be to use a drop-in logging tool like log4net, which will make formatting much more automatic.</p>\n\n<p>If you are going to go the route of two files (and I agree with Craig that a database is probably a better choice,) you can probably save yourself a lot of heartache by having one file that is as sparse as you can make it for later fast searches and one that holds all the information in one place (metadata and data) rather than creating a metadata-only format.</p>\n'}, {'answer_id': 50813, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m going to "split the fence" and say use the database for all of your analysis/archiving log entries (such as your Telnet communications). This will grant you the benefits of full text searching, columns, and easy ways to search out the data.</p>\n\n<p>Use a flat file (or XML format since the file shouldn\'t be too big) for any of your debug/critical error type logs. </p>\n\n<p>If you have a broken database connection, or something has gone wacky with your table structure, logging to the DB will be meaningless.</p>\n\n<p>Come to think of it, if you are looking for a slightly more "lightweight" solution, you could use SQLite to log all your telnet traffic so that you can leverage the advantage of the DB structure, but also have the availability of the file.</p>\n\n<p>With another nod to log4net, you could easily accomplish this with the ADO appender they have.</p>\n'}, {'answer_id': 50827, 'author': 'bmb', 'author_id': 5298, 'author_profile': 'https://Stackoverflow.com/users/5298', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not sure exactly what you are trying to accomplish.  Telnet is usually thought of as a character-at-a-time protocol, so when you say "incoming messages" do you mean each character is a message?  Or the entire user\'s session is a message?</p>\n\n<p>I\'ll make some assumtions.\nYou have users logging in via telnet and you want to capture everything they do while they are logged in.  Later, you want to be able to associate the stuff they did with that user and the time and date they did it.  You\'ll need to be able to search later to find out "who did \'rm *\' as root?"</p>\n\n<p>I would store each user\'s session as a separate file, with a naming convention that includes the user\'s login and a timestamp.</p>\n\n<p>e.g. 2008_09_08_14_52_07_nidonocu</p>\n\n<p>Within the the file, I would capture each byte received, assuming they will mostly be plain text characters.</p>\n\n<p>e.g.</p>\n\n<pre><code>ls\ncd www\nls\nvi index.html\n/copyright 2007\nllllllllllllr8:wq\nexit\n</code></pre>\n\n<p>Write the 8-bit ANSI characters to the file as well.  You should be able to use a text editor and grep to do basic audits and searches.  You could use a binary file viewer or get more sophisticated later if you need to actually read the 8-bit data.</p>\n\n<p>Backups, archiving, purging, etc. can all be done using regular file system tools and scripting.</p>\n\n<p>My apologies if my assumptions are wrong.</p>\n\n<p>--<br>\nBruce</p>\n'}]
['https://Stackoverflow.com/questions/50704', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/483/']