Is there a way to log python print statements in gunicorn?












15















With my Procfile like this:



web: gunicorn app:app 
--bind "$HOST:$PORT"
--debug --error-logfile "-"
--enable-stdio-inheritance
--reload
--log-level "debug"


is it in any way possible to get python print statements to be logged to stdout / bash? I am using the bottle framework here as well, if that affects anything.










share|improve this question























  • The debug flag doesn't apply to gunicorn. It actually fails if you try to run it: gunicorn: error: unrecognized arguments: --debug

    – Akronix
    May 25 '18 at 11:11
















15















With my Procfile like this:



web: gunicorn app:app 
--bind "$HOST:$PORT"
--debug --error-logfile "-"
--enable-stdio-inheritance
--reload
--log-level "debug"


is it in any way possible to get python print statements to be logged to stdout / bash? I am using the bottle framework here as well, if that affects anything.










share|improve this question























  • The debug flag doesn't apply to gunicorn. It actually fails if you try to run it: gunicorn: error: unrecognized arguments: --debug

    – Akronix
    May 25 '18 at 11:11














15












15








15


3






With my Procfile like this:



web: gunicorn app:app 
--bind "$HOST:$PORT"
--debug --error-logfile "-"
--enable-stdio-inheritance
--reload
--log-level "debug"


is it in any way possible to get python print statements to be logged to stdout / bash? I am using the bottle framework here as well, if that affects anything.










share|improve this question














With my Procfile like this:



web: gunicorn app:app 
--bind "$HOST:$PORT"
--debug --error-logfile "-"
--enable-stdio-inheritance
--reload
--log-level "debug"


is it in any way possible to get python print statements to be logged to stdout / bash? I am using the bottle framework here as well, if that affects anything.







python debugging logging bottle gunicorn






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 29 '14 at 11:20









konturkontur

2,8702652




2,8702652













  • The debug flag doesn't apply to gunicorn. It actually fails if you try to run it: gunicorn: error: unrecognized arguments: --debug

    – Akronix
    May 25 '18 at 11:11



















  • The debug flag doesn't apply to gunicorn. It actually fails if you try to run it: gunicorn: error: unrecognized arguments: --debug

    – Akronix
    May 25 '18 at 11:11

















The debug flag doesn't apply to gunicorn. It actually fails if you try to run it: gunicorn: error: unrecognized arguments: --debug

– Akronix
May 25 '18 at 11:11





The debug flag doesn't apply to gunicorn. It actually fails if you try to run it: gunicorn: error: unrecognized arguments: --debug

– Akronix
May 25 '18 at 11:11












3 Answers
3






active

oldest

votes


















17














It turns out the print statements were actually getting through, but with delay.



The gunicorn docs for --enable-stdio-inheritance note to set the PYTHONUNBUFFERED, which I thought I had, but it seems with wrong syntax.



I solved it using a .env file with my foreman setup to set the variable like this:



PYTHONUNBUFFERED=TRUE





share|improve this answer



















  • 6





    Didn't help me :(

    – Wax Cage
    Jun 29 '15 at 11:33











  • Even though it is official way to do it - it does not work for unknown reason (python 2.7)

    – FelikZ
    Nov 4 '16 at 11:55






  • 2





    This works in python3 with Gunicorn + Flask.

    – ATOzTOA
    Jul 13 '17 at 16:44











  • This works in python3 with Gunicorn + Django

    – garej
    Feb 3 '18 at 7:43



















2














Please try below command:



gunicorn --workers 3 --bind 127.0.0.1:5000 --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --capture-output --log-level info


It did work for me.



Please specify log-level to debug(default info)http://docs.gunicorn.org/en/stable/settings.html#loglevel,



Also, specify capture-output flag (default false)http://docs.gunicorn.org/en/stable/settings.html#capture-output.



You should be able to watch logs in error log file.






share|improve this answer































    0














    In python 3, adding flush=True in each print statement works for my flask/gunicorn app.



    E.g.



    gunicorn --bind 0.0.0.0:8080 server --log-level debug


    No particular flags are required.



    See if this helps.






    share|improve this answer























      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%2f27687867%2fis-there-a-way-to-log-python-print-statements-in-gunicorn%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      17














      It turns out the print statements were actually getting through, but with delay.



      The gunicorn docs for --enable-stdio-inheritance note to set the PYTHONUNBUFFERED, which I thought I had, but it seems with wrong syntax.



      I solved it using a .env file with my foreman setup to set the variable like this:



      PYTHONUNBUFFERED=TRUE





      share|improve this answer



















      • 6





        Didn't help me :(

        – Wax Cage
        Jun 29 '15 at 11:33











      • Even though it is official way to do it - it does not work for unknown reason (python 2.7)

        – FelikZ
        Nov 4 '16 at 11:55






      • 2





        This works in python3 with Gunicorn + Flask.

        – ATOzTOA
        Jul 13 '17 at 16:44











      • This works in python3 with Gunicorn + Django

        – garej
        Feb 3 '18 at 7:43
















      17














      It turns out the print statements were actually getting through, but with delay.



      The gunicorn docs for --enable-stdio-inheritance note to set the PYTHONUNBUFFERED, which I thought I had, but it seems with wrong syntax.



      I solved it using a .env file with my foreman setup to set the variable like this:



      PYTHONUNBUFFERED=TRUE





      share|improve this answer



















      • 6





        Didn't help me :(

        – Wax Cage
        Jun 29 '15 at 11:33











      • Even though it is official way to do it - it does not work for unknown reason (python 2.7)

        – FelikZ
        Nov 4 '16 at 11:55






      • 2





        This works in python3 with Gunicorn + Flask.

        – ATOzTOA
        Jul 13 '17 at 16:44











      • This works in python3 with Gunicorn + Django

        – garej
        Feb 3 '18 at 7:43














      17












      17








      17







      It turns out the print statements were actually getting through, but with delay.



      The gunicorn docs for --enable-stdio-inheritance note to set the PYTHONUNBUFFERED, which I thought I had, but it seems with wrong syntax.



      I solved it using a .env file with my foreman setup to set the variable like this:



      PYTHONUNBUFFERED=TRUE





      share|improve this answer













      It turns out the print statements were actually getting through, but with delay.



      The gunicorn docs for --enable-stdio-inheritance note to set the PYTHONUNBUFFERED, which I thought I had, but it seems with wrong syntax.



      I solved it using a .env file with my foreman setup to set the variable like this:



      PYTHONUNBUFFERED=TRUE






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Dec 29 '14 at 12:11









      konturkontur

      2,8702652




      2,8702652








      • 6





        Didn't help me :(

        – Wax Cage
        Jun 29 '15 at 11:33











      • Even though it is official way to do it - it does not work for unknown reason (python 2.7)

        – FelikZ
        Nov 4 '16 at 11:55






      • 2





        This works in python3 with Gunicorn + Flask.

        – ATOzTOA
        Jul 13 '17 at 16:44











      • This works in python3 with Gunicorn + Django

        – garej
        Feb 3 '18 at 7:43














      • 6





        Didn't help me :(

        – Wax Cage
        Jun 29 '15 at 11:33











      • Even though it is official way to do it - it does not work for unknown reason (python 2.7)

        – FelikZ
        Nov 4 '16 at 11:55






      • 2





        This works in python3 with Gunicorn + Flask.

        – ATOzTOA
        Jul 13 '17 at 16:44











      • This works in python3 with Gunicorn + Django

        – garej
        Feb 3 '18 at 7:43








      6




      6





      Didn't help me :(

      – Wax Cage
      Jun 29 '15 at 11:33





      Didn't help me :(

      – Wax Cage
      Jun 29 '15 at 11:33













      Even though it is official way to do it - it does not work for unknown reason (python 2.7)

      – FelikZ
      Nov 4 '16 at 11:55





      Even though it is official way to do it - it does not work for unknown reason (python 2.7)

      – FelikZ
      Nov 4 '16 at 11:55




      2




      2





      This works in python3 with Gunicorn + Flask.

      – ATOzTOA
      Jul 13 '17 at 16:44





      This works in python3 with Gunicorn + Flask.

      – ATOzTOA
      Jul 13 '17 at 16:44













      This works in python3 with Gunicorn + Django

      – garej
      Feb 3 '18 at 7:43





      This works in python3 with Gunicorn + Django

      – garej
      Feb 3 '18 at 7:43













      2














      Please try below command:



      gunicorn --workers 3 --bind 127.0.0.1:5000 --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --capture-output --log-level info


      It did work for me.



      Please specify log-level to debug(default info)http://docs.gunicorn.org/en/stable/settings.html#loglevel,



      Also, specify capture-output flag (default false)http://docs.gunicorn.org/en/stable/settings.html#capture-output.



      You should be able to watch logs in error log file.






      share|improve this answer




























        2














        Please try below command:



        gunicorn --workers 3 --bind 127.0.0.1:5000 --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --capture-output --log-level info


        It did work for me.



        Please specify log-level to debug(default info)http://docs.gunicorn.org/en/stable/settings.html#loglevel,



        Also, specify capture-output flag (default false)http://docs.gunicorn.org/en/stable/settings.html#capture-output.



        You should be able to watch logs in error log file.






        share|improve this answer


























          2












          2








          2







          Please try below command:



          gunicorn --workers 3 --bind 127.0.0.1:5000 --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --capture-output --log-level info


          It did work for me.



          Please specify log-level to debug(default info)http://docs.gunicorn.org/en/stable/settings.html#loglevel,



          Also, specify capture-output flag (default false)http://docs.gunicorn.org/en/stable/settings.html#capture-output.



          You should be able to watch logs in error log file.






          share|improve this answer













          Please try below command:



          gunicorn --workers 3 --bind 127.0.0.1:5000 --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --capture-output --log-level info


          It did work for me.



          Please specify log-level to debug(default info)http://docs.gunicorn.org/en/stable/settings.html#loglevel,



          Also, specify capture-output flag (default false)http://docs.gunicorn.org/en/stable/settings.html#capture-output.



          You should be able to watch logs in error log file.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 21 '18 at 12:32









          SatysSatys

          1,061813




          1,061813























              0














              In python 3, adding flush=True in each print statement works for my flask/gunicorn app.



              E.g.



              gunicorn --bind 0.0.0.0:8080 server --log-level debug


              No particular flags are required.



              See if this helps.






              share|improve this answer




























                0














                In python 3, adding flush=True in each print statement works for my flask/gunicorn app.



                E.g.



                gunicorn --bind 0.0.0.0:8080 server --log-level debug


                No particular flags are required.



                See if this helps.






                share|improve this answer


























                  0












                  0








                  0







                  In python 3, adding flush=True in each print statement works for my flask/gunicorn app.



                  E.g.



                  gunicorn --bind 0.0.0.0:8080 server --log-level debug


                  No particular flags are required.



                  See if this helps.






                  share|improve this answer













                  In python 3, adding flush=True in each print statement works for my flask/gunicorn app.



                  E.g.



                  gunicorn --bind 0.0.0.0:8080 server --log-level debug


                  No particular flags are required.



                  See if this helps.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 4:11









                  jsnceojsnceo

                  82110




                  82110






























                      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%2f27687867%2fis-there-a-way-to-log-python-print-statements-in-gunicorn%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

                      Create new schema in PostgreSQL using DBeaver

                      Deepest pit of an array with Javascript: test on Codility

                      Costa Masnaga