Logging

class uwsgiconf.options.logging.Var(name)
class uwsgiconf.options.logging.VarMetric(name)
class uwsgiconf.options.logging.VarRequestVar(name)
class uwsgiconf.options.logging.Logging(*args, **kwargs)

Logging.

class loggers

Loggers available for add_logger().

file

alias of uwsgiconf.options.logging_loggers.LoggerFile

mongo

alias of uwsgiconf.options.logging_loggers.LoggerMongo

redis

alias of uwsgiconf.options.logging_loggers.LoggerRedis

socket

alias of uwsgiconf.options.logging_loggers.LoggerSocket

syslog

alias of uwsgiconf.options.logging_loggers.LoggerSyslog

rsyslog

alias of uwsgiconf.options.logging_loggers.LoggerRsyslog

zeromq

alias of uwsgiconf.options.logging_loggers.LoggerZeroMq

class encoders

Loggers available for add_logger_encoder().

compress

alias of uwsgiconf.options.logging_encoders.EncoderCompress

format

alias of uwsgiconf.options.logging_encoders.EncoderFormat

gzip

alias of uwsgiconf.options.logging_encoders.EncoderGzip

json

alias of uwsgiconf.options.logging_encoders.EncoderJson

newline

alias of uwsgiconf.options.logging_encoders.EncoderNewline

prefix

alias of uwsgiconf.options.logging_encoders.EncoderPrefix

suffix

alias of uwsgiconf.options.logging_encoders.EncoderSuffix

set_basic_params(no_requests=None, template=None, memory_report=None, prefix=None, prefix_date=None, apply_strftime=None, response_ms=None, ip_x_forwarded=None)
Parameters:
  • no_requests (bool) – Disable requests logging - only uWSGI internal messages and errors will be logged.
  • template (str|unicode) – Set advanced format for request logging. This template string can use variables from Logging.Vars.
  • prefix (str|unicode) – Prefix log items with a string.
  • prefix_date (str|unicode|bool) –

    Prefix log items with date string.

    Note

    This can be True or contain formatting placeholders (e.g. %Y-%m-%d %H:%M:%S) if used with apply_strftime.

  • memory_report (int) – Enable memory report. * 1 - basic (default); * 2 - uss/pss (Linux only)
  • apply_strftime (bool) – Apply strftime to dates in log entries. E.g. prefix_date can contain format placeholders. See also vars.REQ_START_FORMATTED.
  • response_ms (bool) – Report response time in microseconds instead of milliseconds.
  • ip_x_forwarded (bool) – Use the IP from X-Forwarded-For header instead of REMOTE_ADDR. Used when uWSGI is run behind multiple proxies.
log_into(target, before_priv_drop=True)

Simple file or UDP logging.

Note

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

Parameters:
  • target (str|unicode) – Filepath or UDP address.
  • before_priv_drop (bool) – Whether to log data before or after privileges drop.
set_file_params(reopen_on_reload=None, trucate_on_statup=None, max_size=None, rotation_fname=None, touch_reopen=None, touch_rotate=None, owner=None, mode=None)

Set various parameters related to file logging.

Parameters:
  • reopen_on_reload (bool) – Reopen log after reload.
  • trucate_on_statup (bool) – Truncate log on startup.
  • max_size (int) – Set maximum logfile size in bytes after which log should be rotated.
  • rotation_fname (str|unicode) – Set log file name after rotation.
  • touch_reopen (str|unicode|list) –

    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.

  • touch_rotate (str|unicode|list) – Trigger log rotation if the specified file is modified/touched.
  • owner (str|unicode) – Set owner chown() for logs.
  • mode (str|unicode) – Set mode chmod() for logs.
set_filters(include=None, exclude=None, write_errors=None, write_errors_tolerance=None, sigpipe=None)

Set various log data filters.

Parameters:
  • include (str|unicode|list) –

    Show only log lines matching the specified regexp.

    Note

    Requires enabled PCRE support.

  • exclude (str|unicode|list) –

    Do not show log lines matching the specified regexp.

    Note

    Requires enabled PCRE support.

  • write_errors (bool) –

    Log (annoying) write()/writev() errors. Default: True.

    Note

    If both this and sigpipe set to False, it’s the same as setting write-errors-exception-only uWSGI option.

  • write_errors_tolerance (int) –

    Set the maximum number of allowed write errors before exception is raised. Default: no tolerance.

    Note

    Available for Python, Perl, PHP.

  • sigpipe (bool) –

    Log (annoying) SIGPIPE. Default: True.

    Note

    If both this and write_errors set to False, it’s the same as setting write-errors-exception-only uWSGI option.

set_requests_filters(slower=None, bigger=None, status_4xx=None, status_5xx=None, no_body=None, sendfile=None, io_errors=None)

Set various log data filters.

Parameters:
  • slower (int) – Log requests slower than the specified number of milliseconds.
  • bigger (int) – Log requests bigger than the specified size in bytes.
  • status_4xx – Log requests with a 4xx response.
  • status_5xx – Log requests with a 5xx response.
  • no_body (bool) – Log responses without body.
  • sendfile (bool) – Log sendfile requests.
  • io_errors (bool) – Log requests with io errors.
set_master_logging_params(enable=None, dedicate_thread=None, buffer=None, sock_stream=None, sock_stream_requests_only=None)

Sets logging params for delegating logging to master process.

Parameters:
  • enable (bool) – 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.
  • dedicate_thread (bool) –

    Delegate log writing to a thread.

    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.

  • buffer (int) – Set the buffer size for the master logger in bytes. Bigger log messages will be truncated.
  • sock_stream (bool|tuple) – Create the master logpipe as SOCK_STREAM.
  • sock_stream_requests_only (bool|tuple) – Create the master requests logpipe as SOCK_STREAM.
print_loggers()

Print out available (built) loggers.

add_logger(logger, requests_only=False, for_single_worker=False)

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

Parameters:
  • logger (str|unicode|list|Logger|list[Logger]) –
  • requests_only (bool) – Logger used only for requests information messages.
  • for_single_worker (bool) – Logger to be used in single-worker setup.
add_logger_route(logger, matcher, requests_only=False)

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

Parameters:
  • logger (str|unicode|list|Logger|list[Logger]) – Logger to associate route with.
  • matcher (str|unicode) – Regular expression to apply to log item.
  • requests_only (bool) – Matching should be used only for requests information messages.
add_logger_encoder(encoder, logger=None, requests_only=False, for_single_worker=False)

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

Parameters:
  • encoder (str|unicode|list|Encoder) – Encoder (or a list) to add into processing.
  • logger (str|unicode|Logger) – Logger apply associate encoders to.
  • requests_only (bool) – Encoder to be used only for requests information messages.
  • for_single_worker (bool) – Encoder to be used in single-worker setup.
class vars

Variables available for custom log formatting.

REQ_URI = '%(uri)'

REQUEST_URI from wsgi_request of the current request.

REQ_METHOD = '%(method)'

REQUEST_METHOD from wsgi_request of the current request.

REQ_REMOTE_USER = '%(user)'

REMOTE_USER from wsgi_request of the current request.

REQ_REMOTE_ADDR = '%(addr)'

REMOTE_ADDR from wsgi_request of the current request.

REQ_HTTP_HOST = '%(host)'

HTTP_HOST from wsgi_request of the current request.

REQ_SERVER_PROTOCOL = '%(proto)'

SERVER_PROTOCOL from wsgi_request of the current request.

REQ_USER_AGENT = '%(uagent)'

HTTP_USER_AGENT from wsgi_request of the current request.

REQ_REFERER = '%(referer)'

HTTP_REFERER from wsgi_request of the current request.

REQ_START_TS = '%(time)'

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

REQ_START_CTIME = '%(ctime)'

Ctime of the start of the request. E.g.: Thu Dec 7 08:05:35 2017

REQ_START_UNIX_US = '%(tmsecs)'

Timestamp of the start of the request in milliseconds since the epoch.

Note

since 1.9.21

REQ_START_UNIX_MS = '%(tmicros)'

Timestamp of the start of the request in microseconds since the epoch.

Note

since 1.9.21

REQ_START_HUMAN = '%(ltime)'

Human-formatted (Apache style) request time.

REQ_START_FORMATTED = '%(ftime)'

Request time formatted with apply_strftime.

Note

Use apply_strftime and placeholders.

REQ_SIZE_BODY = '%(cl)'

Request content body size.

REQ_COUNT_VARS_CGI = '%(vars)'

Number of CGI vars in the request.

REQ_COUNT_ERR_READ = '%(rerr)'

Number of read errors for the request.

Note

since 1.9.21

REQ_COUNT_ERR_WRITE = '%(werr)'

Number of write errors for the request.

Note

since 1.9.21

REQ_COUNT_ERR = '%(ioerr)'

Number of write and read errors for the request.

Note

since 1.9.21

RESP_STATUS = '%(status)'

HTTP response status code.

RESP_TIME_US = '%(micros)'

Response time in microseconds. E.g.: 1512623650704

RESP_TIME_MS = '%(msecs)'

Response time in milliseconds. E.g.: 1512623650704413

RESP_SIZE = '%(size)'

Response body size + response headers size.

RESP_SIZE_HEADERS = '%(hsize)'

Response headers size.

RESP_SIZE_BODY = '%(rsize)'

Response body size.

RESP_COUNT_HEADERS = '%(headers)'

Number of generated response headers.

TIME_UNIX = '%(epoch)'

The current time in Unix format.

WORKER_PID = '%(pid)'

pid of the worker handling the request.

WORKER_ID = '%(wid)'

id of the worker handling the request.

ASYNC_SWITCHES = '%(switches)'

Number of async switches.

CORE = '%(core)'

The core running the request.

MEM_VSZ = '%(vsz)'

Address space/virtual memory usage (in bytes).

MEM_RSS = '%(rss)'

RSS memory usage (in bytes).

MEM_VSZ_MB = '%(vszM)'

Address space/virtual memory usage (in megabytes).

MEM_RSS_MV = '%(rssM)'

RSS memory usage (in megabytes).

SIZE_PACKET_UWSGI = '%(pktsize)'

Size of the internal request uwsgi packet.

MOD1 = '%(modifier1)'

modifier1 of the request. See .routing.modifiers.

MOD2 = '%(modifier2)'

modifier2 of the request. See .routing.modifiers.

metric

Metric value (see The Metrics subsystem).

alias of VarMetric

request_var

Request variable value.

alias of VarRequestVar