Skip to content

Logging

Classes

Logging


name

.name: str = ''

Name to represent the group.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


add_logger

1
2
3
4
5
.add_logger(
    logger, 
    requests_only: bool = False,  # (1)!
    for_single_worker: bool = False,  # (2)!
)
  1. Logger used only for requests information messages.

  2. Logger to be used in single-worker setup.

Set/add a common logger or a request requests only.


add_logger_encoder

1
2
3
4
5
6
.add_logger_encoder(
    encoder, 
    logger=None, 
    requests_only: bool = False,  # (1)!
    for_single_worker: bool = False,  # (2)!
)
  1. Encoder to be used only for requests information messages.

  2. Encoder to be used in single-worker setup.

Add an item in the log encoder or request encoder chain.


add_logger_route

1
2
3
4
5
.add_logger_route(
    logger, 
    matcher: str,  # (1)!
    requests_only: bool = False,  # (2)!
)
  1. Regular expression to apply to log item.

  2. Matching should be used only for requests information messages.

Log to the specified named logger if regexp applied on log item matches.


log_into

1
2
3
4
.log_into(
    target: str,  # (1)!
    before_priv_drop: bool = True,  # (2)!
)
  1. Filepath or UDP address.

  2. Whether to log data before or after privileges drop.

Simple file or UDP logging.

Note

This doesn't require any Logger plugin and can be used if no log routing is required.


.print_loggers()

Print out available (built) loggers.


set_basic_params

.set_basic_params(
    no_requests: bool | None = None,  # (1)!
    template: str | None = None,  # (2)!
    memory_report: int | None = None,  # (3)!
    prefix: str | None = None,  # (4)!
    prefix_date: Strbool = None,  # (5)!
    apply_strftime: bool | None = None,  # (6)!
    response_ms: bool | None = None,  # (7)!
    ip_x_forwarded: bool | None = None,  # (8)!
)
  1. Disable requests logging - only uWSGI internal messages and errors will be logged.

  2. Set advanced format for request logging. This template string can use variables from Logging.Vars.

  3. Enable memory report.

    • 1 - basic (default);
    • 2 - uss/pss (Linux only)
  4. Prefix log items with a string.

    1
    .. note:: This will not work with `prefix_date` option.
    
  5. Prefix log items with date string.

    1
    2
    3
    4
    .. note:: This will not work with `prefix` option.
    
    .. note:: This can be ``True`` or contain formatting placeholders (e.g. %Y-%m-%d %H:%M:%S) 
       if used with ``apply_strftime``.
    
  6. Apply strftime to dates in log entries. E.g. prefix_date can contain format placeholders. See also vars.REQ_START_FORMATTED.

  7. Report response time in microseconds instead of milliseconds.

  8. Use the IP from X-Forwarded-For header instead of REMOTE_ADDR. Used when uWSGI is run behind multiple proxies.


set_file_params

.set_file_params(
    reopen_on_reload: bool | None = None,  # (1)!
    truncate_on_startup: bool | None = None,  # (2)!
    max_size: int | None = None,  # (3)!
    rotation_fname: str | None = None,  # (4)!
    touch_reopen: Strlist = None,  # (5)!
    touch_rotate: Strlist = None,  # (6)!
    owner: str | None = None,  # (7)!
    mode: str | None = None,  # (8)!
)
  1. Reopen log after reload.

  2. Truncate log on startup.

  3. Set maximum logfile size in bytes after which log should be rotated.

  4. Set log file name after rotation.

  5. Trigger log reopen if the specified file is modified/touched.

    Note

    This can be set to a file touched by postrotate script of logrotate to implement rotation.

  6. Trigger log rotation if the specified file is modified/touched.

  7. Set owner chown() for logs.

  8. Set mode chmod() for logs.

Set various parameters related to file logging.


set_filters

1
2
3
4
5
6
7
.set_filters(
    include: Strlist = None,  # (1)!
    exclude: Strlist = None,  # (2)!
    write_errors: bool | None = None,  # (3)!
    write_errors_tolerance: int | None = None,  # (4)!
    sigpipe: bool | None = None,  # (5)!
)
  1. Show only log lines matching the specified regexp.

    1
    .. note:: Requires enabled PCRE support.
    
  2. Do not show log lines matching the specified regexp.

    1
    .. note:: Requires enabled PCRE support.
    
  3. Log (annoying) write()/writev() errors. Default: True.

    1
    2
    .. note:: If both this and ``sigpipe`` set to ``False``, it's the same
       as setting ``write-errors-exception-only`` uWSGI option.
    
  4. Set the maximum number of allowed write errors before exception is raised. Default: no tolerance.

    Note

    Available for Python, Perl, PHP.

  5. Log (annoying) SIGPIPE. Default: True.

    1
    2
    .. note:: If both this and ``write_errors`` set to ``False``, it's the same
       as setting ``write-errors-exception-only`` uWSGI option.
    

Set various log data filters.


set_master_logging_params

1
2
3
4
5
6
7
.set_master_logging_params(
    enable: bool | None = None,  # (1)!
    dedicate_thread: bool | None = None,  # (2)!
    buffer: int | None = None,  # (3)!
    sock_stream: bool | None = None,  # (4)!
    sock_stream_requests_only: bool | None = None,  # (5)!
)
  1. Delegate logging to master process. Delegate the write of the logs to the master process (this will put all of the logging I/O to a single process). Useful for system with advanced I/O schedulers/elevators.

  2. Delegate log writing to a thread.

    1
    2
    3
    As error situations could cause the master to block while writing
    a log line to a remote server, it may be a good idea to use this option and delegate
    writes to a secondary thread.
    
  3. Set the buffer size for the master logger in bytes. Bigger log messages will be truncated.

  4. Create the master logpipe as SOCK_STREAM.

  5. Create the master requests logpipe as SOCK_STREAM.

Sets logging params for delegating logging to master process.


set_requests_filters

1
2
3
4
5
6
7
8
9
.set_requests_filters(
    slower: int | None = None,  # (1)!
    bigger: int | None = None,  # (2)!
    status_4xx: bool | None = None,  # (3)!
    status_5xx: bool | None = None,  # (4)!
    no_body: bool | None = None,  # (5)!
    sendfile: bool | None = None,  # (6)!
    io_errors: bool | None = None,  # (7)!
)
  1. Log requests slower than the specified number of milliseconds.

  2. Log requests bigger than the specified size in bytes.

  3. Log requests with a 4xx response.

  4. Log requests with a 5xx response.

  5. Log responses without body.

  6. Log sendfile requests.

  7. Log requests with io errors.

Set various log data filters.


encoders

.encoders()

Loggers available for add_logger_encoder().


loggers

.loggers()

Loggers available for add_logger().


vars

.vars()

Variables available for custom log formatting.


ASYNC_SWITCHES
.ASYNC_SWITCHES = '%(switches)'

Number of async switches.


CORE
.CORE = '%(core)'

The core running the request.


MEM_RSS
.MEM_RSS = '%(rss)'

RSS memory usage (in bytes).


MEM_RSS_MV
.MEM_RSS_MV = '%(rssM)'

RSS memory usage (in megabytes).


MEM_VSZ
.MEM_VSZ = '%(vsz)'

Address space/virtual memory usage (in bytes).


MEM_VSZ_MB
.MEM_VSZ_MB = '%(vszM)'

Address space/virtual memory usage (in megabytes).


MOD1
.MOD1 = '%(modifier1)'

modifier1 of the request. See .routing.modifiers.


MOD2
.MOD2 = '%(modifier2)'

modifier2 of the request. See .routing.modifiers.


REQ_COUNT_ERR
.REQ_COUNT_ERR = '%(ioerr)'

Number of write and read errors for the request.

Note

since 1.9.21


REQ_COUNT_ERR_READ
.REQ_COUNT_ERR_READ = '%(rerr)'

Number of read errors for the request.

Note

since 1.9.21


REQ_COUNT_ERR_WRITE
.REQ_COUNT_ERR_WRITE = '%(werr)'

Number of write errors for the request.

Note

since 1.9.21


REQ_COUNT_VARS_CGI
.REQ_COUNT_VARS_CGI = '%(vars)'

Number of CGI vars in the request.


REQ_HTTP_HOST
.REQ_HTTP_HOST = '%(host)'

HTTP_HOST from wsgi_request of the current request.


REQ_METHOD
.REQ_METHOD = '%(method)'

REQUEST_METHOD from wsgi_request of the current request.


REQ_REFERER
.REQ_REFERER = '%(referer)'

HTTP_REFERER from wsgi_request of the current request.


REQ_REMOTE_ADDR
.REQ_REMOTE_ADDR = '%(addr)'

REMOTE_ADDR from wsgi_request of the current request.


REQ_REMOTE_USER
.REQ_REMOTE_USER = '%(user)'

REMOTE_USER from wsgi_request of the current request.


REQ_SERVER_PROTOCOL
.REQ_SERVER_PROTOCOL = '%(proto)'

SERVER_PROTOCOL from wsgi_request of the current request.


REQ_SIZE_BODY
.REQ_SIZE_BODY = '%(cl)'

Request content body size.


REQ_START_CTIME
.REQ_START_CTIME = '%(ctime)'

Ctime of the start of the request. E.g.: Fri May 6 21:44:01 2022


REQ_START_FORMATTED
.REQ_START_FORMATTED = '%(ftime)'

Request time formatted with apply_strftime.

Note

Use apply_strftime and placeholders.


REQ_START_HUMAN
.REQ_START_HUMAN = '%(ltime)'

Human-formatted (Apache style) request time. E.g.: 06/May/2022:21:44:01 +0700


REQ_START_TS
.REQ_START_TS = '%(time)'

Timestamp of the start of the request. E.g.: 1651848241


REQ_START_UNIX_MS
.REQ_START_UNIX_MS = '%(tmicros)'

Timestamp of the start of the request in microseconds since the epoch. E.g.: 1651848241706778

Note

since 1.9.21


REQ_START_UNIX_US
.REQ_START_UNIX_US = '%(tmsecs)'

Timestamp of the start of the request in milliseconds since the epoch. E.g.: 1651848241706

Note

since 1.9.21


REQ_URI
.REQ_URI = '%(uri)'

REQUEST_URI from wsgi_request of the current request.


REQ_USER_AGENT
.REQ_USER_AGENT = '%(uagent)'

HTTP_USER_AGENT from wsgi_request of the current request.


RESP_COUNT_HEADERS
.RESP_COUNT_HEADERS = '%(headers)'

Number of generated response headers.


RESP_SIZE
.RESP_SIZE = '%(size)'

Response body size + response headers size.


RESP_SIZE_BODY
.RESP_SIZE_BODY = '%(rsize)'

Response body size.


RESP_SIZE_HEADERS
.RESP_SIZE_HEADERS = '%(hsize)'

Response headers size.


RESP_STATUS
.RESP_STATUS = '%(status)'

HTTP response status code.


RESP_TIME_MS
.RESP_TIME_MS = '%(msecs)'

Response time in milliseconds. E.g.: 1512623650704413


RESP_TIME_US
.RESP_TIME_US = '%(micros)'

Response time in microseconds. E.g.: 1512623650704


SIZE_PACKET_UWSGI
.SIZE_PACKET_UWSGI = '%(pktsize)'

Size of the internal request uwsgi packet.


TIME_UNIX
.TIME_UNIX = '%(epoch)'

The current time in Unix format. E.g.: 1651848242


WORKER_ID
.WORKER_ID = '%(wid)'

id of the worker handling the request.


WORKER_PID
.WORKER_PID = '%(pid)'

pid of the worker handling the request.


metric
.metric = VarMetric

Metric value (see The Metrics subsystem).


request_var
.request_var = VarRequestVar

Request variable value.