<?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 default python logging is handled in arcgis ? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125279#M9751</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I found something else interesting about writing logs in a text file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://support.esri.com/es/knowledgebase/techarticles/detail/38445"&gt;http://support.esri.com/es/knowledgebase/techarticles/detail/38445&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why not using python logging ? Is it possible it get in conflict with ArcGIS logging configuration ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Aug 2013 07:28:12 GMT</pubDate>
    <dc:creator>SchoppMatthieu</dc:creator>
    <dc:date>2013-08-09T07:28:12Z</dc:date>
    <item>
      <title>how default python logging is handled in arcgis ?</title>
      <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125275#M9747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello I have some difficulties with log files&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that running it from ArcGIS Toolbox interface doesn't give me the same result than running it from python IDLE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In python IDLE, a new logFile is created each time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When executed from ArcGIS toolbox interface, the logFile is only created once and kept in memory. Each time you run the script logs are written in the first logfile (created the first time the script is executed) rather than creating a new one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please have a look at the sample script attached in my second post&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 09:29:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125275#M9747</guid>
      <dc:creator>SchoppMatthieu</dc:creator>
      <dc:date>2013-08-08T09:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: how default python logging is handled in arcgis ?</title>
      <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125276#M9748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have attached the sample of the script with its toolbox.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That would be great if someone could have a quick look.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should notice that running it from python IDLE doesn't give the same result than running it from the toolbox (graphic interface).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Running it from the toolbox graphic interface doesn't recreate the log file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm probably doing something wrong but I can see what it is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 10:58:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125276#M9748</guid>
      <dc:creator>SchoppMatthieu</dc:creator>
      <dc:date>2013-08-08T10:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: how default python logging is handled in arcgis ?</title>
      <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125277#M9749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This script worked perfectly for me, but the scratch directory is different when running from within ArcMap or ArcCatalog. If you look closely your run from IDLE places the file here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\&lt;/SPAN&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;while running from Arc it is placed here (emphasis placed on difference):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;C:\Users\ADMINI~1\AppData\Local\Temp\2\&lt;STRONG&gt;arc4BFD\&lt;/STRONG&gt;scratch\&lt;/SPAN&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For me there was even a difference between running from ArcMap and running from ArcCatalog.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 20:53:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125277#M9749</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2013-08-08T20:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: how default python logging is handled in arcgis ?</title>
      <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125278#M9750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for having a look at it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is surprising that it is not working for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the problem I can see :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are two 'print' 'addMessage' in the script&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- The name and directory of the logfile I want to create&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- The actual log handlers base file&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.AddMessage("my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : "+str(outputFileLog))
print ("my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : "+str(outputFileLog))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for handler in logger.handlers:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ("my log file handler : "+handler.baseFilename)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run this from python IDLE my two prints appear in the console and they match each other, which is what I want :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; 
my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_f4ccc4d1-00c3-11e3-835e-123142ff4c42.log
I'm getting here
my log file handler : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_f4ccc4d1-00c3-11e3-835e-123142ff4c42.log
&amp;gt;&amp;gt;&amp;gt; ================================ RESTART ================================
&amp;gt;&amp;gt;&amp;gt; 
my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_0e69ed9e-00c4-11e3-840d-123142ff4c42.log
I'm getting here
my log file handler : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_0e69ed9e-00c4-11e3-840d-123142ff4c42.log
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It means a new log file is created each time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However each time I run it from the toolbox graphic interface, a new file handler pointing to the correct logfile is created but previous ones are not released and logs are written in all of them (see attachment).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I publish it to the server, not even new logs are created, the geoprocessing service just keep writing in the first log generated the first time the service started. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could it be related to the way logs are managed in ArcGIS, I saw this in the ArcGIS Server &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#//0093000000mv000000" rel="nofollow noopener noreferrer" target="_blank"&gt;documentation&lt;/A&gt;&lt;SPAN&gt; that looks really similar to the problem I'm experiencing :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]By default, the log files are written to &amp;lt;installation_location&amp;gt;\server\user\log on every machine. Each time ArcGIS Server restarts, new log files are created, and the server will continue to write messages to those log files until they reach the maximum log size.[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, uuid, os, logging
from arcpy import env

env.overwriteOutput = True

outputDir = arcpy.env.scratchFolder
outputName = 'WebMap_{}'.format(str(uuid.uuid1()))
outputLogName = outputName + r".log"
outputFileLog = os.path.join(outputDir, outputLogName)


arcpy.AddMessage("my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : "+str(outputFileLog))
print ("my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : "+str(outputFileLog))

def createLogger(logFile):

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("I'm getting here")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print ("I'm getting here")

&amp;nbsp;&amp;nbsp;&amp;nbsp; logger = logging.getLogger(__name__)
&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.setLevel(logging.INFO)

&amp;nbsp;&amp;nbsp;&amp;nbsp; for handler in logger.handlers:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : "+handler.baseFilename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ("my log file handler : "+handler.baseFilename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; handler=[]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; handler = logging.FileHandler(logFile)
&amp;nbsp;&amp;nbsp;&amp;nbsp; handler.setLevel(logging.INFO)

&amp;nbsp;&amp;nbsp;&amp;nbsp; formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
&amp;nbsp;&amp;nbsp;&amp;nbsp; handler.setFormatter(formatter)
&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.addHandler(handler)

&amp;nbsp;&amp;nbsp;&amp;nbsp; for handler in logger.handlers:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("my log file name&amp;nbsp;&amp;nbsp;&amp;nbsp; : "+handler.baseFilename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ("my log file handler : "+handler.baseFilename)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return logger


logger = createLogger(outputFileLog)

logger.info("I'm created")

del logger
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm afraid I will have to write logs on a plain text file...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:08:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125278#M9750</guid>
      <dc:creator>SchoppMatthieu</dc:creator>
      <dc:date>2021-12-11T07:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: how default python logging is handled in arcgis ?</title>
      <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125279#M9751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I found something else interesting about writing logs in a text file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://support.esri.com/es/knowledgebase/techarticles/detail/38445"&gt;http://support.esri.com/es/knowledgebase/techarticles/detail/38445&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why not using python logging ? Is it possible it get in conflict with ArcGIS logging configuration ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 07:28:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125279#M9751</guid>
      <dc:creator>SchoppMatthieu</dc:creator>
      <dc:date>2013-08-09T07:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: how default python logging is handled in arcgis ?</title>
      <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125280#M9752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not 100% sure what you're trying to accomplish, but I'll explain how scratch works when using arcpy.env.scratchFolder like you are.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When you're in the app (ArcMap, ArcCatalog, etc), the scratchFolder will always be a folder called "scratch" in the directory of that applications scratchworkspace environment. So you can control this location by setting the scratchworkspace environment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If a scratchworkspace has not been set, the location defaults to the user who is running the application temp directory. One of the things we did at 10.1 was introduce a temp folder with a unique id, usually arc#### inside the temp directory. This assists with clean up. As your screen shots are pointing there, I assume you're running your tools from ArcCatalog - as by default Catalog doesn't usually set a scratchworkspace and the scratchFolder environment is failing over into a known location.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you run your scrips from Python, ie. NOT inside the application, they make use of whoever is running it's temp directory. Basically the same as above, except no unique arc####. Again, if you explicitly set the scratchworkspace in the script, the scratchFolder will get created/used there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With ArcGIS Server, every execution of a GP Service happens in a new folder, designated by a GUID. In each of these folders a new scratch directory gets created. It is here your output gets created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope by knowing the rules of "Scratch" it'll hep you move forward.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These help links offer a little more info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://blogs.esri.com/esri/arcgis/2012/10/19/the-new-scratchgdb-and-scratchfolder-environments/"&gt;http://blogs.esri.com/esri/arcgis/2012/10/19/the-new-scratchgdb-and-scratchfolder-environments/&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001w00000046000000"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//001w00000046000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 14:17:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125280#M9752</guid>
      <dc:creator>KevinHibma</dc:creator>
      <dc:date>2013-08-09T14:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: how default python logging is handled in arcgis ?</title>
      <link>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125281#M9753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello khibma, I hope you didn't spend too much time writing your answer, I have absolutely no problem with the scratch directory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem comes from log files that are not released when executed from the toolbox.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I solved it by using a text file instead of using 'logging' facilities.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 07:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-default-python-logging-is-handled-in-arcgis/m-p/125281#M9753</guid>
      <dc:creator>SchoppMatthieu</dc:creator>
      <dc:date>2013-08-12T07:14:55Z</dc:date>
    </item>
  </channel>
</rss>

