Giter Site home page Giter Site logo

Can't change TransLogger format about paste HOT 4 CLOSED

ariksa avatar ariksa commented on September 6, 2024
Can't change TransLogger format

from paste.

Comments (4)

ariksa avatar ariksa commented on September 6, 2024 1

You are right, I saw that dictionary and hence opened this issue.
But I can't fight maintenance mode :)
Thanks, closing.

from paste.

cdent avatar cdent commented on September 6, 2024

Can you provide the MY_FORMAT that you are using that fails, and the traceback that happens when it fails? Without that it's hard to narrow down the issue.

from paste.

ariksa avatar ariksa commented on September 6, 2024

I wanted to go with a standard logging format:
MY_FORMAT = '[%(levelname)s] (%(filename)s:%(lineno)d) - %(message)s'

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/waitress/channel.py", line 356, in service
    task.service()
  File "/usr/lib/python3.6/site-packages/waitress/task.py", line 176, in service
    self.execute()
  File "/usr/lib/python3.6/site-packages/waitress/task.py", line 447, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/usr/lib/python3.6/site-packages/paste/translogger.py", line 69, in __call__
    return self.application(environ, replacement_start_response)
  File "/usr/lib/python3.6/site-packages/connexion/apps/abstract.py", line 248, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 2328, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 2318, in wsgi_app
    return response(environ, start_response)
  File "/usr/lib/python3.6/site-packages/werkzeug/wrappers/base_response.py", line 701, in __call__
    start_response(status, headers)
  File "/usr/lib/python3.6/site-packages/paste/translogger.py", line 67, in replacement_start_response
    self.write_log(environ, method, req_uri, start, status, bytes)
  File "/usr/lib/python3.6/site-packages/paste/translogger.py", line 99, in write_log
    message = self.format % d
KeyError: 'levelname'

from paste.

cdent avatar cdent commented on September 6, 2024

Ah, okay. As you've probably already determined, there is a defined set of variables that you can provide, using Translogger, the left hand side in this dict:

        d = {                                                                   
            'REMOTE_ADDR': remote_addr,                                         
            'REMOTE_USER': environ.get('REMOTE_USER') or '-',                   
            'REQUEST_METHOD': method,                                           
            'REQUEST_URI': req_uri,                                             
            'HTTP_VERSION': environ.get('SERVER_PROTOCOL'),                     
            'time': time.strftime('%d/%b/%Y:%H:%M:%S ', start) + offset,        
            'status': status.split(None, 1)[0],                                 
            'bytes': bytes,                                                     
            'HTTP_REFERER': environ.get('HTTP_REFERER', '-'),                   
            'HTTP_USER_AGENT': environ.get('HTTP_USER_AGENT', '-'),             
            }                                        

To get the output that you want you're probably better off using either a different logging middleware, or a subclass of Translogger.

In any case, given that paste is in maintenance mode, and the code is behaving as designed (setting aside for the moment whether that design is good), this is not something that's going to change.

I'm not certain, but I suspect either waitress or flask should be able to provide you with different modes of logging that could fit your needs.

If all that makes sense, please close the issue.

from paste.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.