mirror of
https://github.com/dkmstr/openuds.git
synced 2025-03-26 02:50:35 +03:00
Merge remote-tracking branch 'origin/v3.6'
This commit is contained in:
commit
bcf185d54a
@ -181,8 +181,6 @@ class Handler:
|
||||
else:
|
||||
self._user = User() # Empty user for non authenticated handlers
|
||||
|
||||
# Keep track of the operation
|
||||
log.log_operation(self)
|
||||
|
||||
def headers(self) -> typing.Dict[str, str]:
|
||||
"""
|
||||
|
@ -30,30 +30,41 @@
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import typing
|
||||
import datetime
|
||||
|
||||
from uds.models import Log, getSqlDatetime
|
||||
from uds.core.util import log, config
|
||||
from uds.core.jobs import Job
|
||||
from uds.core.util.log import (
|
||||
REST,
|
||||
OWNER_TYPE_REST,
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARNING,
|
||||
ERROR,
|
||||
CRITICAL,
|
||||
# These are legacy support until full removal
|
||||
WARN,
|
||||
FATAL,
|
||||
)
|
||||
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from .handlers import Handler
|
||||
|
||||
|
||||
def log_operation(handler: 'Handler', level: int = log.INFO):
|
||||
def log_operation(handler: typing.Optional['Handler'], response_code: int, level: int = INFO):
|
||||
"""
|
||||
Logs a request
|
||||
"""
|
||||
if not handler:
|
||||
return # Nothing to log
|
||||
username = handler._request.user.pretty_name if handler._request.user else 'Unknown'
|
||||
# Global log is used without owner nor type
|
||||
Log.objects.create(
|
||||
owner_id=0,
|
||||
owner_type=log.OWNER_TYPE_REST,
|
||||
owner_type=OWNER_TYPE_REST,
|
||||
created=getSqlDatetime(),
|
||||
level=level,
|
||||
source=log.REST,
|
||||
data=f'{username}: [{handler._request.method}] {handler._request.path}'[
|
||||
source=REST,
|
||||
data=f'{username}: [{handler._request.method}/{response_code}] {handler._request.path}'[
|
||||
:255
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -43,10 +43,13 @@ logger = logging.getLogger(__name__)
|
||||
useLogger = logging.getLogger('useLog')
|
||||
|
||||
# Logging levels
|
||||
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (
|
||||
OTHER, DEBUG, INFO, WARNING, ERROR, CRITICAL = (
|
||||
10000 * (x + 1) for x in range(6)
|
||||
) # @UndefinedVariable
|
||||
|
||||
WARN = WARNING
|
||||
FATAL = CRITICAL
|
||||
|
||||
# Logging sources
|
||||
INTERNAL, ACTOR, TRANSPORT, OSMANAGER, UNKNOWN, WEB, ADMIN, SERVICE, REST = (
|
||||
'internal',
|
||||
|
Loading…
x
Reference in New Issue
Block a user