<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to force Python to write a log file to specified location? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-force-python-to-write-a-log-file-to/m-p/355033#M27925</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I need to see is a log showing the success or failure of the Python portion of the code.&lt;BR /&gt;Is there a way of getting Python to dump a log file out to specific location while it is running in SAS?&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If "print" and arcpy.AddMessage() output is not captured by SAS, yes, the only thing left is to write a log file somewhere.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need a try/except to capture a message if the script fails, for example&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;try: &amp;nbsp;&amp;nbsp;&amp;nbsp; ... do your work ... except Exception, msg: &amp;nbsp;&amp;nbsp;&amp;nbsp; errMsg = "script failed\n" + str(msg) &amp;nbsp;&amp;nbsp;&amp;nbsp; # write a message to gp out &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(errMsg) &amp;nbsp;&amp;nbsp;&amp;nbsp; # print a message to stdout &amp;nbsp;&amp;nbsp;&amp;nbsp; print&amp;nbsp; "** " + errMsg &amp;nbsp;&amp;nbsp;&amp;nbsp; # write to a log file &amp;nbsp;&amp;nbsp;&amp;nbsp; f.open("c:\\temp\\out.txt","w") &amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(errMsg + "\n") &amp;nbsp;&amp;nbsp;&amp;nbsp; f.close()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Oct 2012 19:49:10 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2012-10-29T19:49:10Z</dc:date>
    <item>
      <title>How to force Python to write a log file to specified location?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-force-python-to-write-a-log-file-to/m-p/355032#M27924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Forum users,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running a SAS script that uses a Python script to work on an ArcGIS 10 SDE Feature Class. The Python script does everything to the Feature Class it is supposed to do but when it finishes does not leave a record of its success or failure in the SAS log tab. The SAS log only sees Python opening and then once it is finished closing. What I need to see is a log showing the success or failure of the Python portion of the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way of getting Python to dump a log file out to specific location while it is running in SAS?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any input you may have.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Greg&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ps. I think it???s time to take a Python course!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 17:38:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-force-python-to-write-a-log-file-to/m-p/355032#M27924</guid>
      <dc:creator>GregParent</dc:creator>
      <dc:date>2012-10-29T17:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to force Python to write a log file to specified location?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-force-python-to-write-a-log-file-to/m-p/355033#M27925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I need to see is a log showing the success or failure of the Python portion of the code.&lt;BR /&gt;Is there a way of getting Python to dump a log file out to specific location while it is running in SAS?&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If "print" and arcpy.AddMessage() output is not captured by SAS, yes, the only thing left is to write a log file somewhere.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need a try/except to capture a message if the script fails, for example&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;try: &amp;nbsp;&amp;nbsp;&amp;nbsp; ... do your work ... except Exception, msg: &amp;nbsp;&amp;nbsp;&amp;nbsp; errMsg = "script failed\n" + str(msg) &amp;nbsp;&amp;nbsp;&amp;nbsp; # write a message to gp out &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(errMsg) &amp;nbsp;&amp;nbsp;&amp;nbsp; # print a message to stdout &amp;nbsp;&amp;nbsp;&amp;nbsp; print&amp;nbsp; "** " + errMsg &amp;nbsp;&amp;nbsp;&amp;nbsp; # write to a log file &amp;nbsp;&amp;nbsp;&amp;nbsp; f.open("c:\\temp\\out.txt","w") &amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(errMsg + "\n") &amp;nbsp;&amp;nbsp;&amp;nbsp; f.close()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 19:49:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-force-python-to-write-a-log-file-to/m-p/355033#M27925</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-10-29T19:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to force Python to write a log file to specified location?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-force-python-to-write-a-log-file-to/m-p/355034#M27926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;check out logging:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2/library/logging.html"&gt;http://docs.python.org/2/library/logging.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2012 09:42:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-force-python-to-write-a-log-file-to/m-p/355034#M27926</guid>
      <dc:creator>FabianBlau</dc:creator>
      <dc:date>2012-10-30T09:42:46Z</dc:date>
    </item>
  </channel>
</rss>

