How to capture STDOUT of a Python process running under IIS, FastCGI, and WSGI?












3















I have a Python Flask app. When I run it from PowerShell, I can see the stream of output coming from calls to functions like print() and logging.info() throughout my code.



When I point IIS to my app and have it run through FastCGI with a web.config file, where does that output stream go? How can I capture it to a log file?










share|improve this question



























    3















    I have a Python Flask app. When I run it from PowerShell, I can see the stream of output coming from calls to functions like print() and logging.info() throughout my code.



    When I point IIS to my app and have it run through FastCGI with a web.config file, where does that output stream go? How can I capture it to a log file?










    share|improve this question

























      3












      3








      3








      I have a Python Flask app. When I run it from PowerShell, I can see the stream of output coming from calls to functions like print() and logging.info() throughout my code.



      When I point IIS to my app and have it run through FastCGI with a web.config file, where does that output stream go? How can I capture it to a log file?










      share|improve this question














      I have a Python Flask app. When I run it from PowerShell, I can see the stream of output coming from calls to functions like print() and logging.info() throughout my code.



      When I point IIS to my app and have it run through FastCGI with a web.config file, where does that output stream go? How can I capture it to a log file?







      python iis wsgi fastcgi






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 6 '15 at 18:09









      sffcsffc

      3,45512445




      3,45512445
























          1 Answer
          1






          active

          oldest

          votes


















          2














          There are 3 kinds of log files when you use FastCGI/WSGI.



          Let's name them:




          • WSGI log


            • File name from the example below: wsgi_myapp.log

            • gets the stream (StdOut, StdErr) from wsgi main script

            • For example when you publish new version of your page to the server, wsgi will restart and the messages about restarting goes there.

            • Another example is when your application encounters uncaught error, it saves the traceback into this file



          • App log


            • File name from the example below: myapp.log

            • Here goes everything what you want to log throught app.logger.LEVEL("..."), considering the right LEVEL is set on the logger as well as on the handler



          • HTTP requests log


            • Not a part of my code example below

            • The logs of the requests received by your HTTP server

            • You can change the location and behavior of this log from within IIS Logging settings of the web page

            • you can see these during the development alongside your own prints and log messages

            • Example from flask: "[2019-01-12 21:08:00,748] INFO in _internal: 127.0.0.1 - - [12/Jan/2019 21:08:00] "GET /static/js/jquery-3.3.1.min.js HTTP/1.1" 304 -

            • Example from ISS: 2019-01-12 20:42:41 10.175.214.88 GET /static/js/jquery-ui.min.js 80 ****USER**** ****IP**** Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/70.0.3538.110+Safari/537.36 http://yourweb.com/smthing 304 0 0 1875




          See this example:



          from flask import Flask
          from logging.config import dictConfig

          dictConfig({
          'version': 1,
          'formatters': {'default': {
          'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
          }},
          'handlers': {
          'wsgi': {
          'class': 'logging.StreamHandler',
          'formatter': 'default'
          },
          'custom_handler': {
          'class': 'logging.FileHandler',
          'formatter': 'default',
          'filename': r'C:inetpubwwwrootmyapplogsmyapp.log'
          }
          },
          'root': {
          'level': 'INFO',
          'handlers': ['wsgi', 'custom_handler']
          }
          })

          app = Flask(__name__)

          # other imports using logger should go here
          # from a import b
          # ...


          and the web.config file:



          <configuration>
          <system.webServer>
          <handlers>
          <remove name="Python FastCGI" />
          <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="E:Python362_64python.exe|E:Python362_64Libsite-packageswfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
          </handlers>
          <urlCompression doStaticCompression="true" doDynamicCompression="true" />
          </system.webServer>
          <appSettings>
          <!-- Required settings -->
          <add key="WSGI_HANDLER" value="myapp.app" />
          <add key="PYTHONPATH" value="C:inetpubwwwrootmyapp" />
          <add key="SCRIPT_NAME" value="/myapp" />
          <add key="WSGI_LOG" value="C:inetpubwwwrootmyapplogswsgi_myapp.log" />
          <add key="WSGI_RESTART_FILE_REGEX" value=".*((.py)|(.config))$" />
          </appSettings>
          </configuration>





          share|improve this answer


























          • Could you clarify what goes into wsgi_myapp.log vs myapp.log?

            – Dennis George
            Jan 11 at 17:43






          • 1





            See my edited post :-)

            – Peter Majko
            Jan 12 at 20:47











          • 👌 perfect, thank you!

            – Dennis George
            Jan 12 at 23:18











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31862873%2fhow-to-capture-stdout-of-a-python-process-running-under-iis-fastcgi-and-wsgi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          There are 3 kinds of log files when you use FastCGI/WSGI.



          Let's name them:




          • WSGI log


            • File name from the example below: wsgi_myapp.log

            • gets the stream (StdOut, StdErr) from wsgi main script

            • For example when you publish new version of your page to the server, wsgi will restart and the messages about restarting goes there.

            • Another example is when your application encounters uncaught error, it saves the traceback into this file



          • App log


            • File name from the example below: myapp.log

            • Here goes everything what you want to log throught app.logger.LEVEL("..."), considering the right LEVEL is set on the logger as well as on the handler



          • HTTP requests log


            • Not a part of my code example below

            • The logs of the requests received by your HTTP server

            • You can change the location and behavior of this log from within IIS Logging settings of the web page

            • you can see these during the development alongside your own prints and log messages

            • Example from flask: "[2019-01-12 21:08:00,748] INFO in _internal: 127.0.0.1 - - [12/Jan/2019 21:08:00] "GET /static/js/jquery-3.3.1.min.js HTTP/1.1" 304 -

            • Example from ISS: 2019-01-12 20:42:41 10.175.214.88 GET /static/js/jquery-ui.min.js 80 ****USER**** ****IP**** Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/70.0.3538.110+Safari/537.36 http://yourweb.com/smthing 304 0 0 1875




          See this example:



          from flask import Flask
          from logging.config import dictConfig

          dictConfig({
          'version': 1,
          'formatters': {'default': {
          'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
          }},
          'handlers': {
          'wsgi': {
          'class': 'logging.StreamHandler',
          'formatter': 'default'
          },
          'custom_handler': {
          'class': 'logging.FileHandler',
          'formatter': 'default',
          'filename': r'C:inetpubwwwrootmyapplogsmyapp.log'
          }
          },
          'root': {
          'level': 'INFO',
          'handlers': ['wsgi', 'custom_handler']
          }
          })

          app = Flask(__name__)

          # other imports using logger should go here
          # from a import b
          # ...


          and the web.config file:



          <configuration>
          <system.webServer>
          <handlers>
          <remove name="Python FastCGI" />
          <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="E:Python362_64python.exe|E:Python362_64Libsite-packageswfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
          </handlers>
          <urlCompression doStaticCompression="true" doDynamicCompression="true" />
          </system.webServer>
          <appSettings>
          <!-- Required settings -->
          <add key="WSGI_HANDLER" value="myapp.app" />
          <add key="PYTHONPATH" value="C:inetpubwwwrootmyapp" />
          <add key="SCRIPT_NAME" value="/myapp" />
          <add key="WSGI_LOG" value="C:inetpubwwwrootmyapplogswsgi_myapp.log" />
          <add key="WSGI_RESTART_FILE_REGEX" value=".*((.py)|(.config))$" />
          </appSettings>
          </configuration>





          share|improve this answer


























          • Could you clarify what goes into wsgi_myapp.log vs myapp.log?

            – Dennis George
            Jan 11 at 17:43






          • 1





            See my edited post :-)

            – Peter Majko
            Jan 12 at 20:47











          • 👌 perfect, thank you!

            – Dennis George
            Jan 12 at 23:18
















          2














          There are 3 kinds of log files when you use FastCGI/WSGI.



          Let's name them:




          • WSGI log


            • File name from the example below: wsgi_myapp.log

            • gets the stream (StdOut, StdErr) from wsgi main script

            • For example when you publish new version of your page to the server, wsgi will restart and the messages about restarting goes there.

            • Another example is when your application encounters uncaught error, it saves the traceback into this file



          • App log


            • File name from the example below: myapp.log

            • Here goes everything what you want to log throught app.logger.LEVEL("..."), considering the right LEVEL is set on the logger as well as on the handler



          • HTTP requests log


            • Not a part of my code example below

            • The logs of the requests received by your HTTP server

            • You can change the location and behavior of this log from within IIS Logging settings of the web page

            • you can see these during the development alongside your own prints and log messages

            • Example from flask: "[2019-01-12 21:08:00,748] INFO in _internal: 127.0.0.1 - - [12/Jan/2019 21:08:00] "GET /static/js/jquery-3.3.1.min.js HTTP/1.1" 304 -

            • Example from ISS: 2019-01-12 20:42:41 10.175.214.88 GET /static/js/jquery-ui.min.js 80 ****USER**** ****IP**** Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/70.0.3538.110+Safari/537.36 http://yourweb.com/smthing 304 0 0 1875




          See this example:



          from flask import Flask
          from logging.config import dictConfig

          dictConfig({
          'version': 1,
          'formatters': {'default': {
          'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
          }},
          'handlers': {
          'wsgi': {
          'class': 'logging.StreamHandler',
          'formatter': 'default'
          },
          'custom_handler': {
          'class': 'logging.FileHandler',
          'formatter': 'default',
          'filename': r'C:inetpubwwwrootmyapplogsmyapp.log'
          }
          },
          'root': {
          'level': 'INFO',
          'handlers': ['wsgi', 'custom_handler']
          }
          })

          app = Flask(__name__)

          # other imports using logger should go here
          # from a import b
          # ...


          and the web.config file:



          <configuration>
          <system.webServer>
          <handlers>
          <remove name="Python FastCGI" />
          <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="E:Python362_64python.exe|E:Python362_64Libsite-packageswfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
          </handlers>
          <urlCompression doStaticCompression="true" doDynamicCompression="true" />
          </system.webServer>
          <appSettings>
          <!-- Required settings -->
          <add key="WSGI_HANDLER" value="myapp.app" />
          <add key="PYTHONPATH" value="C:inetpubwwwrootmyapp" />
          <add key="SCRIPT_NAME" value="/myapp" />
          <add key="WSGI_LOG" value="C:inetpubwwwrootmyapplogswsgi_myapp.log" />
          <add key="WSGI_RESTART_FILE_REGEX" value=".*((.py)|(.config))$" />
          </appSettings>
          </configuration>





          share|improve this answer


























          • Could you clarify what goes into wsgi_myapp.log vs myapp.log?

            – Dennis George
            Jan 11 at 17:43






          • 1





            See my edited post :-)

            – Peter Majko
            Jan 12 at 20:47











          • 👌 perfect, thank you!

            – Dennis George
            Jan 12 at 23:18














          2












          2








          2







          There are 3 kinds of log files when you use FastCGI/WSGI.



          Let's name them:




          • WSGI log


            • File name from the example below: wsgi_myapp.log

            • gets the stream (StdOut, StdErr) from wsgi main script

            • For example when you publish new version of your page to the server, wsgi will restart and the messages about restarting goes there.

            • Another example is when your application encounters uncaught error, it saves the traceback into this file



          • App log


            • File name from the example below: myapp.log

            • Here goes everything what you want to log throught app.logger.LEVEL("..."), considering the right LEVEL is set on the logger as well as on the handler



          • HTTP requests log


            • Not a part of my code example below

            • The logs of the requests received by your HTTP server

            • You can change the location and behavior of this log from within IIS Logging settings of the web page

            • you can see these during the development alongside your own prints and log messages

            • Example from flask: "[2019-01-12 21:08:00,748] INFO in _internal: 127.0.0.1 - - [12/Jan/2019 21:08:00] "GET /static/js/jquery-3.3.1.min.js HTTP/1.1" 304 -

            • Example from ISS: 2019-01-12 20:42:41 10.175.214.88 GET /static/js/jquery-ui.min.js 80 ****USER**** ****IP**** Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/70.0.3538.110+Safari/537.36 http://yourweb.com/smthing 304 0 0 1875




          See this example:



          from flask import Flask
          from logging.config import dictConfig

          dictConfig({
          'version': 1,
          'formatters': {'default': {
          'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
          }},
          'handlers': {
          'wsgi': {
          'class': 'logging.StreamHandler',
          'formatter': 'default'
          },
          'custom_handler': {
          'class': 'logging.FileHandler',
          'formatter': 'default',
          'filename': r'C:inetpubwwwrootmyapplogsmyapp.log'
          }
          },
          'root': {
          'level': 'INFO',
          'handlers': ['wsgi', 'custom_handler']
          }
          })

          app = Flask(__name__)

          # other imports using logger should go here
          # from a import b
          # ...


          and the web.config file:



          <configuration>
          <system.webServer>
          <handlers>
          <remove name="Python FastCGI" />
          <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="E:Python362_64python.exe|E:Python362_64Libsite-packageswfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
          </handlers>
          <urlCompression doStaticCompression="true" doDynamicCompression="true" />
          </system.webServer>
          <appSettings>
          <!-- Required settings -->
          <add key="WSGI_HANDLER" value="myapp.app" />
          <add key="PYTHONPATH" value="C:inetpubwwwrootmyapp" />
          <add key="SCRIPT_NAME" value="/myapp" />
          <add key="WSGI_LOG" value="C:inetpubwwwrootmyapplogswsgi_myapp.log" />
          <add key="WSGI_RESTART_FILE_REGEX" value=".*((.py)|(.config))$" />
          </appSettings>
          </configuration>





          share|improve this answer















          There are 3 kinds of log files when you use FastCGI/WSGI.



          Let's name them:




          • WSGI log


            • File name from the example below: wsgi_myapp.log

            • gets the stream (StdOut, StdErr) from wsgi main script

            • For example when you publish new version of your page to the server, wsgi will restart and the messages about restarting goes there.

            • Another example is when your application encounters uncaught error, it saves the traceback into this file



          • App log


            • File name from the example below: myapp.log

            • Here goes everything what you want to log throught app.logger.LEVEL("..."), considering the right LEVEL is set on the logger as well as on the handler



          • HTTP requests log


            • Not a part of my code example below

            • The logs of the requests received by your HTTP server

            • You can change the location and behavior of this log from within IIS Logging settings of the web page

            • you can see these during the development alongside your own prints and log messages

            • Example from flask: "[2019-01-12 21:08:00,748] INFO in _internal: 127.0.0.1 - - [12/Jan/2019 21:08:00] "GET /static/js/jquery-3.3.1.min.js HTTP/1.1" 304 -

            • Example from ISS: 2019-01-12 20:42:41 10.175.214.88 GET /static/js/jquery-ui.min.js 80 ****USER**** ****IP**** Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/70.0.3538.110+Safari/537.36 http://yourweb.com/smthing 304 0 0 1875




          See this example:



          from flask import Flask
          from logging.config import dictConfig

          dictConfig({
          'version': 1,
          'formatters': {'default': {
          'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
          }},
          'handlers': {
          'wsgi': {
          'class': 'logging.StreamHandler',
          'formatter': 'default'
          },
          'custom_handler': {
          'class': 'logging.FileHandler',
          'formatter': 'default',
          'filename': r'C:inetpubwwwrootmyapplogsmyapp.log'
          }
          },
          'root': {
          'level': 'INFO',
          'handlers': ['wsgi', 'custom_handler']
          }
          })

          app = Flask(__name__)

          # other imports using logger should go here
          # from a import b
          # ...


          and the web.config file:



          <configuration>
          <system.webServer>
          <handlers>
          <remove name="Python FastCGI" />
          <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="E:Python362_64python.exe|E:Python362_64Libsite-packageswfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
          </handlers>
          <urlCompression doStaticCompression="true" doDynamicCompression="true" />
          </system.webServer>
          <appSettings>
          <!-- Required settings -->
          <add key="WSGI_HANDLER" value="myapp.app" />
          <add key="PYTHONPATH" value="C:inetpubwwwrootmyapp" />
          <add key="SCRIPT_NAME" value="/myapp" />
          <add key="WSGI_LOG" value="C:inetpubwwwrootmyapplogswsgi_myapp.log" />
          <add key="WSGI_RESTART_FILE_REGEX" value=".*((.py)|(.config))$" />
          </appSettings>
          </configuration>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 12 at 20:46

























          answered Nov 13 '18 at 11:24









          Peter MajkoPeter Majko

          625515




          625515













          • Could you clarify what goes into wsgi_myapp.log vs myapp.log?

            – Dennis George
            Jan 11 at 17:43






          • 1





            See my edited post :-)

            – Peter Majko
            Jan 12 at 20:47











          • 👌 perfect, thank you!

            – Dennis George
            Jan 12 at 23:18



















          • Could you clarify what goes into wsgi_myapp.log vs myapp.log?

            – Dennis George
            Jan 11 at 17:43






          • 1





            See my edited post :-)

            – Peter Majko
            Jan 12 at 20:47











          • 👌 perfect, thank you!

            – Dennis George
            Jan 12 at 23:18

















          Could you clarify what goes into wsgi_myapp.log vs myapp.log?

          – Dennis George
          Jan 11 at 17:43





          Could you clarify what goes into wsgi_myapp.log vs myapp.log?

          – Dennis George
          Jan 11 at 17:43




          1




          1





          See my edited post :-)

          – Peter Majko
          Jan 12 at 20:47





          See my edited post :-)

          – Peter Majko
          Jan 12 at 20:47













          👌 perfect, thank you!

          – Dennis George
          Jan 12 at 23:18





          👌 perfect, thank you!

          – Dennis George
          Jan 12 at 23:18


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31862873%2fhow-to-capture-stdout-of-a-python-process-running-under-iis-fastcgi-and-wsgi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values