event_loggers – Example loggers

Example event logger classes.

New in version 3.11.

These loggers can be registered using register() or MongoClient.

monitoring.register(CommandLogger())

or

MongoClient(event_listeners=[CommandLogger()])

class pymongo.event_loggers.``CommandLogger

A simple listener that logs command events.

Listens for CommandStartedEvent, CommandSucceededEvent and CommandFailedEvent events and logs them at the INFO severity level using logging. .. versionadded:: 3.11

  • failed(event)

    Abstract method to handle a CommandFailedEvent.

    Parameters:
    • event: An instance of CommandFailedEvent.
  • started(event)

    Abstract method to handle a CommandStartedEvent.

    Parameters:
    • event: An instance of CommandStartedEvent.
  • succeeded(event)

    Abstract method to handle a CommandSucceededEvent.

    Parameters:
    • event: An instance of CommandSucceededEvent.

class pymongo.event_loggers.``ConnectionPoolLogger

A simple listener that logs server connection pool events.

Listens for PoolCreatedEvent, PoolClearedEvent, PoolClosedEvent, :~pymongo.monitoring.class:ConnectionCreatedEvent, ConnectionReadyEvent, ConnectionClosedEvent, ConnectionCheckOutStartedEvent, ConnectionCheckOutFailedEvent, ConnectionCheckedOutEvent, and ConnectionCheckedInEvent events and logs them at the INFO severity level using logging.

New in version 3.11.

  • connection_check_out_failed(event)

    Abstract method to handle a ConnectionCheckOutFailedEvent.

    Emitted when the driver’s attempt to check out a connection fails.

    Parameters:
    • event: An instance of ConnectionCheckOutFailedEvent.
  • connection_check_out_started(event)

    Abstract method to handle a ConnectionCheckOutStartedEvent.

    Emitted when the driver starts attempting to check out a connection.

    Parameters:
    • event: An instance of ConnectionCheckOutStartedEvent.
  • connection_checked_in(event)

    Abstract method to handle a ConnectionCheckedInEvent.

    Emitted when the driver checks in a Connection back to the Connection Pool.

    Parameters:
    • event: An instance of ConnectionCheckedInEvent.
  • connection_checked_out(event)

    Abstract method to handle a ConnectionCheckedOutEvent.

    Emitted when the driver successfully checks out a Connection.

    Parameters:
    • event: An instance of ConnectionCheckedOutEvent.
  • connection_closed(event)

    Abstract method to handle a ConnectionClosedEvent.

    Emitted when a Connection Pool closes a Connection.

    Parameters:
    • event: An instance of ConnectionClosedEvent.
  • connection_created(event)

    Abstract method to handle a ConnectionCreatedEvent.

    Emitted when a Connection Pool creates a Connection object.

    Parameters:
    • event: An instance of ConnectionCreatedEvent.
  • connection_ready(event)

    Abstract method to handle a ConnectionReadyEvent.

    Emitted when a Connection has finished its setup, and is now ready to use.

    Parameters:
    • event: An instance of ConnectionReadyEvent.
  • pool_cleared(event)

    Abstract method to handle a PoolClearedEvent.

    Emitted when a Connection Pool is cleared.

    Parameters:
    • event: An instance of PoolClearedEvent.
  • pool_closed(event)

    Abstract method to handle a PoolClosedEvent.

    Emitted when a Connection Pool is closed.

    Parameters:
    • event: An instance of PoolClosedEvent.
  • pool_created(event)

    Abstract method to handle a PoolCreatedEvent.

    Emitted when a Connection Pool is created.

    Parameters:
    • event: An instance of PoolCreatedEvent.

class pymongo.event_loggers.``HeartbeatLogger

A simple listener that logs server heartbeat events.

Listens for ServerHeartbeatStartedEvent, ServerHeartbeatSucceededEvent, and ServerHeartbeatFailedEvent events and logs them at the INFO severity level using logging.

New in version 3.11.

  • failed(event)

    Abstract method to handle a ServerHeartbeatFailedEvent.

    Parameters:
    • event: An instance of ServerHeartbeatFailedEvent.
  • started(event)

    Abstract method to handle a ServerHeartbeatStartedEvent.

    Parameters:
    • event: An instance of ServerHeartbeatStartedEvent.
  • succeeded(event)

    Abstract method to handle a ServerHeartbeatSucceededEvent.

    Parameters:
    • event: An instance of ServerHeartbeatSucceededEvent.

class pymongo.event_loggers.``ServerLogger

A simple listener that logs server discovery events.

Listens for ServerOpeningEvent, ServerDescriptionChangedEvent, and ServerClosedEvent events and logs them at the INFO severity level using logging.

New in version 3.11.

  • closed(event)

    Abstract method to handle a ServerClosedEvent.

    Parameters:
    • event: An instance of ServerClosedEvent.
  • description_changed(event)

    Abstract method to handle a ServerDescriptionChangedEvent.

    Parameters:
    • event: An instance of ServerDescriptionChangedEvent.
  • opened(event)

    Abstract method to handle a ServerOpeningEvent.

    Parameters:
    • event: An instance of ServerOpeningEvent.

class pymongo.event_loggers.``TopologyLogger

A simple listener that logs server topology events.

Listens for TopologyOpenedEvent, TopologyDescriptionChangedEvent, and TopologyClosedEvent events and logs them at the INFO severity level using logging.

New in version 3.11.

  • closed(event)

    Abstract method to handle a TopologyClosedEvent.

    Parameters:
    • event: An instance of TopologyClosedEvent.
  • description_changed(event)

    Abstract method to handle a TopologyDescriptionChangedEvent.

    Parameters:
    • event: An instance of TopologyDescriptionChangedEvent.
  • opened(event)

    Abstract method to handle a TopologyOpenedEvent.

    Parameters:
    • event: An instance of TopologyOpenedEvent.

Previous topic

write_concern – Tools for specifying write concern

Next topic

gridfs – Tools for working with GridFS

This Page

Quick search