Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python_logging_rabbitmq/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def __init__(self, level=logging.NOTSET, formatter=None,
fields=None, fields_under_root=True, message_headers=None,
record_fields=None, exclude_record_fields=None,
heartbeat=60,
content_type='text/plain'):
content_type='text/plain',
expiration=None):
# Initialize the handler.
#
# :param level: Logs level.
Expand All @@ -49,6 +50,7 @@ def __init__(self, level=logging.NOTSET, formatter=None,
# :exclude_record_fields: A set of attributes that should be ignored from the record object.
# :heartbeat: Lower bound for heartbeat timeout.
# :content_type: The format of the message sent to the queue.
# :expiration: Expiry time (ms) for RabbitMQ messages (str or None).

super(RabbitMQHandler, self).__init__(level=level)

Expand All @@ -74,6 +76,7 @@ def __init__(self, level=logging.NOTSET, formatter=None,
# Extra params for message publication
self.message_headers = message_headers
self.content_type = content_type
self.expiration = expiration

# Save routing-key formatter.
self.routing_key_formatter = routing_key_formatter
Expand Down Expand Up @@ -172,6 +175,7 @@ def emit(self, record):
properties=pika.BasicProperties(
delivery_mode=2,
headers=self.message_headers,
expiration=self.expiration,
content_type=self.content_type
)
)
Expand Down
6 changes: 5 additions & 1 deletion python_logging_rabbitmq/handlers_oneway.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, level=logging.NOTSET, formatter=None,
fields=None, fields_under_root=True, message_headers=None,
record_fields=None, exclude_record_fields=None,
heartbeat=60,
content_type='text/plain'):
content_type='text/plain',
expiration=None):
# Initialize the handler.
#
# :param level: Logs level.
Expand All @@ -53,6 +54,7 @@ def __init__(self, level=logging.NOTSET, formatter=None,
# :exclude_record_fields: A set of attributes that should be ignored from the record object.
# :heartbeat: Lower bound for heartbeat timeout.
# :content_type: The format of the message sent to the queue.
# :expiration: Expiry time (ms) for RabbitMQ messages (str or None).

super(RabbitMQHandlerOneWay, self).__init__(level=level)

Expand All @@ -78,6 +80,7 @@ def __init__(self, level=logging.NOTSET, formatter=None,
# Extra params for message publication
self.message_headers = message_headers
self.content_type = content_type
self.expiration = expiration

# Save routing-key formatter.
self.routing_key_formatter = routing_key_formatter
Expand Down Expand Up @@ -171,6 +174,7 @@ def message_worker(self):
properties=pika.BasicProperties(
delivery_mode=2,
headers=self.message_headers,
expiration=self.expiration,
content_type=self.content_type
)
)
Expand Down