<tfoot id='QUp7W'></tfoot>

    <legend id='QUp7W'><style id='QUp7W'><dir id='QUp7W'><q id='QUp7W'></q></dir></style></legend>
  • <i id='QUp7W'><tr id='QUp7W'><dt id='QUp7W'><q id='QUp7W'><span id='QUp7W'><b id='QUp7W'><form id='QUp7W'><ins id='QUp7W'></ins><ul id='QUp7W'></ul><sub id='QUp7W'></sub></form><legend id='QUp7W'></legend><bdo id='QUp7W'><pre id='QUp7W'><center id='QUp7W'></center></pre></bdo></b><th id='QUp7W'></th></span></q></dt></tr></i><div id='QUp7W'><tfoot id='QUp7W'></tfoot><dl id='QUp7W'><fieldset id='QUp7W'></fieldset></dl></div>

    <small id='QUp7W'></small><noframes id='QUp7W'>

      <bdo id='QUp7W'></bdo><ul id='QUp7W'></ul>

        保存日志 - SimpleHTTPServer

        时间:2023-10-19

            <bdo id='Bp0b2'></bdo><ul id='Bp0b2'></ul>
            <i id='Bp0b2'><tr id='Bp0b2'><dt id='Bp0b2'><q id='Bp0b2'><span id='Bp0b2'><b id='Bp0b2'><form id='Bp0b2'><ins id='Bp0b2'></ins><ul id='Bp0b2'></ul><sub id='Bp0b2'></sub></form><legend id='Bp0b2'></legend><bdo id='Bp0b2'><pre id='Bp0b2'><center id='Bp0b2'></center></pre></bdo></b><th id='Bp0b2'></th></span></q></dt></tr></i><div id='Bp0b2'><tfoot id='Bp0b2'></tfoot><dl id='Bp0b2'><fieldset id='Bp0b2'></fieldset></dl></div>

          • <small id='Bp0b2'></small><noframes id='Bp0b2'>

                <tbody id='Bp0b2'></tbody>
            1. <legend id='Bp0b2'><style id='Bp0b2'><dir id='Bp0b2'><q id='Bp0b2'></q></dir></style></legend>

                <tfoot id='Bp0b2'></tfoot>
                • 本文介绍了保存日志 - SimpleHTTPServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何保存控制台的输出,例如

                  How can I save the output from the console like

                  192.168.1.1 - - [18/Aug/2014 12:05:59] 代码 404,消息文件未找到"

                  "192.168.1.1 - - [18/Aug/2014 12:05:59] code 404, message File not found"

                  到一个文件?

                  代码如下:

                  import SimpleHTTPServer
                  import SocketServer
                  
                  PORT = 1548
                  
                  Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
                  
                  httpd = SocketServer.TCPServer(("", PORT), Handler)
                  
                  print "serving at port", PORT
                  
                  httpd.serve_forever()
                  

                  推荐答案

                  BaseHTTPRequestHandler.log_message() 通过写入 sys.stderr 打印所有日志消息.你有两个选择:

                  BaseHTTPRequestHandler.log_message() prints all log messages by writing to sys.stderr. You have two choices:

                  1) 继续使用BaseHTTPRequestHandler.log_message(),但是改变sys.stderr的值:

                  1) Continue using BaseHTTPRequestHandler.log_message(), but change the value of sys.stderr:

                  import SimpleHTTPServer
                  import SocketServer
                  
                  PORT = 1548
                  
                  Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
                  
                  httpd = SocketServer.TCPServer(("", PORT), Handler)
                  
                  print "serving at port", PORT
                  
                  import sys
                  buffer = 1
                  sys.stderr = open('logfile.txt', 'w', buffer)
                  httpd.serve_forever()
                  

                  2) 新建一个xxxRequestHandler类,替换.log_message():

                  2) Create a new xxxRequestHandler class, replacing .log_message():

                  import SimpleHTTPServer
                  import SocketServer
                  import sys
                  
                  PORT = 1548
                  
                  class MyHTTPHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
                      buffer = 1
                      log_file = open('logfile.txt', 'w', buffer)
                      def log_message(self, format, *args):
                          self.log_file.write("%s - - [%s] %s
                  " %
                                              (self.client_address[0],
                                               self.log_date_time_string(),
                                               format%args))
                  
                  Handler = MyHTTPHandler
                  
                  httpd = SocketServer.TCPServer(("", PORT), Handler)
                  
                  print "serving at port", PORT
                  
                  httpd.serve_forever()
                  

                  这篇关于保存日志 - SimpleHTTPServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何为基于文本的 python rpg 制作保存/加载游戏? 下一篇:Julia 中 Python 的 ast.literal_eval() 等价物是什么?

                  相关文章

                • <small id='ahlvc'></small><noframes id='ahlvc'>

                  • <bdo id='ahlvc'></bdo><ul id='ahlvc'></ul>

                  <i id='ahlvc'><tr id='ahlvc'><dt id='ahlvc'><q id='ahlvc'><span id='ahlvc'><b id='ahlvc'><form id='ahlvc'><ins id='ahlvc'></ins><ul id='ahlvc'></ul><sub id='ahlvc'></sub></form><legend id='ahlvc'></legend><bdo id='ahlvc'><pre id='ahlvc'><center id='ahlvc'></center></pre></bdo></b><th id='ahlvc'></th></span></q></dt></tr></i><div id='ahlvc'><tfoot id='ahlvc'></tfoot><dl id='ahlvc'><fieldset id='ahlvc'></fieldset></dl></div>

                  1. <tfoot id='ahlvc'></tfoot>

                    1. <legend id='ahlvc'><style id='ahlvc'><dir id='ahlvc'><q id='ahlvc'></q></dir></style></legend>