<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://bftech.darkstormstudios.co.uk/index.php?action=history&amp;feed=atom&amp;title=Debugging</id>
	<title>Debugging - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bftech.darkstormstudios.co.uk/index.php?action=history&amp;feed=atom&amp;title=Debugging"/>
	<link rel="alternate" type="text/html" href="https://bftech.darkstormstudios.co.uk/index.php?title=Debugging&amp;action=history"/>
	<updated>2026-11-01T20:56:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://bftech.darkstormstudios.co.uk/index.php?title=Debugging&amp;diff=24&amp;oldid=prev</id>
		<title>Administrator at 20:36, 5 September 2011</title>
		<link rel="alternate" type="text/html" href="https://bftech.darkstormstudios.co.uk/index.php?title=Debugging&amp;diff=24&amp;oldid=prev"/>
		<updated>2011-09-05T20:36:43Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:36, 5 September 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The BF2 engine has some debugging features, one of which is a log file that it can produce during the course of a game that records various pieces of information that would be useful in debugging. This BF2 engine log file can be written to from Python programs by using the &amp;lt;code&amp;gt;host.log(msg)&amp;lt;/code&amp;gt; method. Unfortunately, no one seems to know how to turn this logging on right now--maybe it&amp;#039;s a command-line option? It&amp;#039;s even possible that the debugging features were stripped out of the retail version of the BF2 server, and so the log may be non-existent.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The BF2 engine has some debugging features, one of which is a log file that it can produce during the course of a game that records various pieces of information that would be useful in debugging. This BF2 engine log file can be written to from Python programs by using the &amp;lt;code&amp;gt;host.log(msg)&amp;lt;/code&amp;gt; method. Unfortunately, no one seems to know how to turn this logging on right now--maybe it&amp;#039;s a command-line option? It&amp;#039;s even possible that the debugging features were stripped out of the retail version of the BF2 server, and so the log may be non-existent.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l11&quot;&gt;Line 11:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;So, why is this any good if &amp;lt;code&amp;gt;host.log&amp;lt;/code&amp;gt; is a black hole? Because you can redirect redirect stdout and stderr yourself, to your own log file. . . inside &amp;lt;code&amp;gt;bf2.init_module&amp;lt;/code&amp;gt; (in the file &amp;lt;code&amp;gt;Battlefield 2 Server/python/__init__.py&amp;lt;/code&amp;gt;, then look for the line that says &amp;quot;&amp;lt;code&amp;gt;def init_module():&amp;lt;/code&amp;gt;&amp;quot;), look for the code that reads&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;So, why is this any good if &amp;lt;code&amp;gt;host.log&amp;lt;/code&amp;gt; is a black hole? Because you can redirect redirect stdout and stderr yourself, to your own log file. . . inside &amp;lt;code&amp;gt;bf2.init_module&amp;lt;/code&amp;gt; (in the file &amp;lt;code&amp;gt;Battlefield 2 Server/python/__init__.py&amp;lt;/code&amp;gt;, then look for the line that says &amp;quot;&amp;lt;code&amp;gt;def init_module():&amp;lt;/code&amp;gt;&amp;quot;), look for the code that reads&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt; sys.stdout = fake_stream(&#039;stdout&#039;) sys.stderr = fake_stream(&#039;stderr&#039;) &amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;style=&quot;white-space: pre-wrap&quot;&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;sys.stdout = fake_stream(&#039;stdout&#039;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;sys.stderr = fake_stream(&#039;stderr&#039;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;and replace it with:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;and replace it with:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;style=&quot;white-space: pre-wrap&quot;&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt; logFile = open(&#039;mylogfile.log&#039;, &#039;a&#039;) sys.stdout = logFile sys.stderr = logFile &amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;logFile = open(&#039;mylogfile.log&#039;, &#039;a&#039;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;sys.stdout = logFile&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;sys.stderr = logFile&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(The &amp;lt;code&amp;gt;&amp;#039;a&amp;#039;&amp;lt;/code&amp;gt; means that Python should &amp;quot;append&amp;quot; output to the end of the log file, as opposed to erasing it first). This change will cause anything every error message and the output of every &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; statement to be routed to the file &amp;lt;code&amp;gt;Battlefield 2 Server/mylogfile.log&amp;lt;/code&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(The &amp;lt;code&amp;gt;&amp;#039;a&amp;#039;&amp;lt;/code&amp;gt; means that Python should &amp;quot;append&amp;quot; output to the end of the log file, as opposed to erasing it first). This change will cause anything every error message and the output of every &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; statement to be routed to the file &amp;lt;code&amp;gt;Battlefield 2 Server/mylogfile.log&amp;lt;/code&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://bftech.darkstormstudios.co.uk/index.php?title=Debugging&amp;diff=23&amp;oldid=prev</id>
		<title>Administrator: Created page with &quot;  The BF2 engine has some debugging features, one of which is a log file that it can produce during the course of a game that records various pieces of information that would be ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bftech.darkstormstudios.co.uk/index.php?title=Debugging&amp;diff=23&amp;oldid=prev"/>
		<updated>2011-09-05T20:31:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;  The BF2 engine has some debugging features, one of which is a log file that it can produce during the course of a game that records various pieces of information that would be ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
The BF2 engine has some debugging features, one of which is a log file that it can produce during the course of a game that records various pieces of information that would be useful in debugging. This BF2 engine log file can be written to from Python programs by using the &amp;lt;code&amp;gt;host.log(msg)&amp;lt;/code&amp;gt; method. Unfortunately, no one seems to know how to turn this logging on right now--maybe it&amp;#039;s a command-line option? It&amp;#039;s even possible that the debugging features were stripped out of the retail version of the BF2 server, and so the log may be non-existent.&lt;br /&gt;
&lt;br /&gt;
The core DICE Python code includes a Python debugging feature that sends it&amp;#039;s output to the BF2 engine log file via &amp;lt;code&amp;gt;host.log&amp;lt;/code&amp;gt;. It does this by redefining the stdout (standard output) and stderr (standard error message) I/O streams so that instead of going to the console (which is basically non-existent for the embedded Python interpreter), they are routed to &amp;lt;code&amp;gt;host.log&amp;lt;/code&amp;gt;, where they will be recorded along with any log information from the BF2 engine. Once this redefinition is done, a simple Python &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; statement will send its output to the log file.&lt;br /&gt;
&lt;br /&gt;
The classes used to accomplish this output redirection are defined in &amp;lt;code&amp;gt;bf2.__init__&amp;lt;/code&amp;gt;, but the actual redirection itself doesn&amp;#039;t happen until the BF2 engine calls the &amp;lt;code&amp;gt;bf2.init_module()&amp;lt;/code&amp;gt;. . . so any &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; statements executed before this will go nowhere.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;bf2.__init__&amp;lt;/code&amp;gt; module, close to the beginning of the file, is a line that says: &amp;lt;code&amp;gt;g_debug = 0&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;g_debug&amp;lt;/code&amp;gt; serves as a global flag that activates (=1) or deactivates (=0) the printing of debugging information throughout all BF2 Python modules. Throughout the DICE Python code, whenever the program has a bit of information that might be useful in debugging (often just a statement that &amp;quot;we reached this point&amp;quot;), the code checks the value of &amp;lt;code&amp;gt;g_debug&amp;lt;/code&amp;gt;, and if it&amp;#039;s 1, it prints the debugging information. (If you want to use g_debug as a switch for debugging information from your own modules, be sure to put &amp;lt;code&amp;gt;from bf2 import g_debug&amp;lt;/code&amp;gt; in those modules).&lt;br /&gt;
&lt;br /&gt;
So, why is this any good if &amp;lt;code&amp;gt;host.log&amp;lt;/code&amp;gt; is a black hole? Because you can redirect redirect stdout and stderr yourself, to your own log file. . . inside &amp;lt;code&amp;gt;bf2.init_module&amp;lt;/code&amp;gt; (in the file &amp;lt;code&amp;gt;Battlefield 2 Server/python/__init__.py&amp;lt;/code&amp;gt;, then look for the line that says &amp;quot;&amp;lt;code&amp;gt;def init_module():&amp;lt;/code&amp;gt;&amp;quot;), look for the code that reads&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; sys.stdout = fake_stream(&amp;#039;stdout&amp;#039;) sys.stderr = fake_stream(&amp;#039;stderr&amp;#039;) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; logFile = open(&amp;#039;mylogfile.log&amp;#039;, &amp;#039;a&amp;#039;) sys.stdout = logFile sys.stderr = logFile &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(The &amp;lt;code&amp;gt;&amp;#039;a&amp;#039;&amp;lt;/code&amp;gt; means that Python should &amp;quot;append&amp;quot; output to the end of the log file, as opposed to erasing it first). This change will cause anything every error message and the output of every &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; statement to be routed to the file &amp;lt;code&amp;gt;Battlefield 2 Server/mylogfile.log&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can now use &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; statements in your own Python code as a way of getting feedback about what&amp;#039;s going on in your programming.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: Because of the way your operating system buffers I/O, you may not see anything in your log file until the &amp;lt;code&amp;gt;stdout&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;stderr&amp;lt;/code&amp;gt; streams are closed or until the operating system&amp;#039;s internal buffer is full--which may not happen for quite a while. . . and maybe not until the server is shut down--and even then, your output may vanish completely if the server isn&amp;#039;t shutdown in an orderly way. For example, if you are using the server GUI tool available from EA and you push the &amp;quot;Stop&amp;quot; button when the server is running, the server will shutdown abruptly without flushing it&amp;#039;s buffers--and you&amp;#039;ll find nothing in your log file. To shut the server down gracefully, type the &amp;quot;quit&amp;quot; command into the server&amp;#039;s window directly. If you&amp;#039;ve sent some particularly important information to the log file and you want to insure it gets there, you can use the &amp;lt;code&amp;gt;sys.stdout.flush()&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
NOTE: You can use host.rcon_invoke(&amp;#039;echo &amp;quot;...&amp;quot;&amp;#039;) to print things directly to the server console.&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
</feed>