Comments (3)
can i please be assigned to this issue ?
from hug.
sure, I tried this code, but get requests still trashing my container's log
class SilentGetLoggingMiddleware(hug.middleware.LoggingMiddleware):
def log(self, request, response=None):
if request.method != 'GET':
super().log(request, response)
api = hug.API(__name__)
api.http.add_middleware(CORSMiddleware(api, allow_origins=["*"]))
api.http.add_middleware(SilentGetLoggingMiddleware())
from hug.
it seems there's an issue with the hug.middleware.LoggingMiddleware
not being silent for GET requests. To work around this, you can use the standard Python logging module directly to configure logging
and filter out GET requests.
`import hug
from hug.middleware import CORSMiddleware
import logging
from src.libs.versionMiddleware import VersionMiddleware
class SilentGetLoggingMiddleware:
def process_request(self, request, response):
if request.method == 'GET':
return None
return True
api = hug.API(name)
api.http.add_middleware(CORSMiddleware(api, allow_origins=["*"]))
api.http.add_middleware(SilentGetLoggingMiddleware())
api.http.add_middleware(VersionMiddleware('prometheus-version'))
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
@hug.get('/')
def hello():
return "Hello, World!"
`
In this example, I've created a SilentGetLoggingMiddleware
class that implements the process_request
method. This method checks if the request method is GET and returns None to skip the logging for GET requests. Otherwise, it returns True
to allow the request to be processed and logged.
Additionally, the logging
module is configured directly using basicConfig
to set the logging level and format.
from hug.
Related Issues (20)
- zsh: command not found: hug HOT 1
- How to configure a service?
- Bug: dashed versions of valid command line arguments fail silently
- Add exception in not_found router
- Missing explicit python 3.8 compatibility from release note.
- GET endpoints not working when using prefixes in @hug.object.urls
- Tag the source
- Remove pinning
- pytest-runner not required HOT 1
- distutils has been deprecated in Python 3.10 HOT 1
- Is this project abandoned? HOT 8
- Unexpected conversion during a requests.post() operation
- TypeError: gather() got an unexpected keyword argument 'loop' HOT 2
- CORS Middleware help
- Exception handler: Why find a potential handler doesn't exit the loop
- Implementation bugs for exception catching!
- FYI: cgi module is deprecated in Python 3.11, will be removed in 3.13
- Could you please clarify this deprecation warning?! HOT 2
- Inconsistent indentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hug.