How do I prevent a python server from writing to the terminal window?












0















I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:enter image description here



I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL), I've tried logger.propagation = False, and logger.disable = True



This is my server code:



os.chdir("docs")
port = 8980
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", port), Handler) as httpd:
httpd.serve_forever()









share|improve this question



























    0















    I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:enter image description here



    I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL), I've tried logger.propagation = False, and logger.disable = True



    This is my server code:



    os.chdir("docs")
    port = 8980
    Handler = http.server.SimpleHTTPRequestHandler
    with socketserver.TCPServer(("", port), Handler) as httpd:
    httpd.serve_forever()









    share|improve this question

























      0












      0








      0








      I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:enter image description here



      I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL), I've tried logger.propagation = False, and logger.disable = True



      This is my server code:



      os.chdir("docs")
      port = 8980
      Handler = http.server.SimpleHTTPRequestHandler
      with socketserver.TCPServer(("", port), Handler) as httpd:
      httpd.serve_forever()









      share|improve this question














      I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:enter image description here



      I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL), I've tried logger.propagation = False, and logger.disable = True



      This is my server code:



      os.chdir("docs")
      port = 8980
      Handler = http.server.SimpleHTTPRequestHandler
      with socketserver.TCPServer(("", port), Handler) as httpd:
      httpd.serve_forever()






      python logging webserver






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 1:48









      F4TornadoF4Tornado

      4817




      4817
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Subclass SimpleHTTPRequestHandler and override the log_message method to do nothing:



          class QuietHandler(http.server.SimpleHTTPRequestHandler):
          def log_message(self, format, *args):
          pass


          with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
          httpd.serve_forever()





          share|improve this answer































            1














            One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
            python3 myserver.py 2> nul






            share|improve this answer































              0














              I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.



              If you're wanting to redirect to file, you can use os.write to print to file.



              If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:



              noop = logging.NullHandler()
              log.addHandler(noop)
              # nothing happens here
              log.info('message that will not be logged')


              Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.






              share|improve this answer
























              • It doesn't really matter where the message goes, just that it's not visible on the terminal windows.

                – F4Tornado
                Nov 23 '18 at 3:29











              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%2f53422825%2fhow-do-i-prevent-a-python-server-from-writing-to-the-terminal-window%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









              1














              Subclass SimpleHTTPRequestHandler and override the log_message method to do nothing:



              class QuietHandler(http.server.SimpleHTTPRequestHandler):
              def log_message(self, format, *args):
              pass


              with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
              httpd.serve_forever()





              share|improve this answer




























                1














                Subclass SimpleHTTPRequestHandler and override the log_message method to do nothing:



                class QuietHandler(http.server.SimpleHTTPRequestHandler):
                def log_message(self, format, *args):
                pass


                with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
                httpd.serve_forever()





                share|improve this answer


























                  1












                  1








                  1







                  Subclass SimpleHTTPRequestHandler and override the log_message method to do nothing:



                  class QuietHandler(http.server.SimpleHTTPRequestHandler):
                  def log_message(self, format, *args):
                  pass


                  with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
                  httpd.serve_forever()





                  share|improve this answer













                  Subclass SimpleHTTPRequestHandler and override the log_message method to do nothing:



                  class QuietHandler(http.server.SimpleHTTPRequestHandler):
                  def log_message(self, format, *args):
                  pass


                  with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
                  httpd.serve_forever()






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 2:10









                  codycody

                  6,12621125




                  6,12621125

























                      1














                      One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
                      python3 myserver.py 2> nul






                      share|improve this answer




























                        1














                        One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
                        python3 myserver.py 2> nul






                        share|improve this answer


























                          1












                          1








                          1







                          One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
                          python3 myserver.py 2> nul






                          share|improve this answer













                          One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
                          python3 myserver.py 2> nul







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 22 '18 at 1:55









                          user2704561user2704561

                          1815




                          1815























                              0














                              I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.



                              If you're wanting to redirect to file, you can use os.write to print to file.



                              If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:



                              noop = logging.NullHandler()
                              log.addHandler(noop)
                              # nothing happens here
                              log.info('message that will not be logged')


                              Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.






                              share|improve this answer
























                              • It doesn't really matter where the message goes, just that it's not visible on the terminal windows.

                                – F4Tornado
                                Nov 23 '18 at 3:29
















                              0














                              I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.



                              If you're wanting to redirect to file, you can use os.write to print to file.



                              If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:



                              noop = logging.NullHandler()
                              log.addHandler(noop)
                              # nothing happens here
                              log.info('message that will not be logged')


                              Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.






                              share|improve this answer
























                              • It doesn't really matter where the message goes, just that it's not visible on the terminal windows.

                                – F4Tornado
                                Nov 23 '18 at 3:29














                              0












                              0








                              0







                              I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.



                              If you're wanting to redirect to file, you can use os.write to print to file.



                              If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:



                              noop = logging.NullHandler()
                              log.addHandler(noop)
                              # nothing happens here
                              log.info('message that will not be logged')


                              Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.






                              share|improve this answer













                              I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.



                              If you're wanting to redirect to file, you can use os.write to print to file.



                              If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:



                              noop = logging.NullHandler()
                              log.addHandler(noop)
                              # nothing happens here
                              log.info('message that will not be logged')


                              Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 22 '18 at 2:16









                              scp31442scp31442

                              265




                              265













                              • It doesn't really matter where the message goes, just that it's not visible on the terminal windows.

                                – F4Tornado
                                Nov 23 '18 at 3:29



















                              • It doesn't really matter where the message goes, just that it's not visible on the terminal windows.

                                – F4Tornado
                                Nov 23 '18 at 3:29

















                              It doesn't really matter where the message goes, just that it's not visible on the terminal windows.

                              – F4Tornado
                              Nov 23 '18 at 3:29





                              It doesn't really matter where the message goes, just that it's not visible on the terminal windows.

                              – F4Tornado
                              Nov 23 '18 at 3:29


















                              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%2f53422825%2fhow-do-i-prevent-a-python-server-from-writing-to-the-terminal-window%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

                              MongoDB - Not Authorized To Execute Command

                              in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                              How to fix TextFormField cause rebuild widget in Flutter