<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def capture(self, pattern=None, negate=False, workers=None, negate_workers=False, params=None, success=False, error=True, stats=False):
 """Starts capturing selected events in real-time. You can filter exactly what you want to see, as the Clearly Server handles all tasks and workers updates being sent to celery. Several clients can see different sets of events at the same time. This runs in the foreground, so you can see in real-time exactly what your clients and celery workers are doing. Press CTRL+C at any time to stop it. Args: Filter args: pattern (Optional[str]):
 a pattern to filter tasks to capture. ex.: '^dispatch|^email' to filter names starting with that or 'dispatch.*123456' to filter that exact name and number or even '123456' to filter that exact number anywhere. negate (bool):
 if True, finds tasks that do not match criteria. workers (Optional[str]):
 a pattern to filter workers to capture. ex.: 'service|priority' to filter names containing that negate_workers (bool):
 if True, finds workers that do not match criteria. Display args: params (Optional[bool]):
 if True shows args and kwargs in the first and last seen states, if False never shows, and if None follows the success and error arguments. default is None success (bool):
 if True shows successful tasks' results. default is False error (bool):
 if True shows failed and retried tasks' tracebacks. default is True, as you're monitoring to find errors, right? stats (bool):
 if True shows complete workers' stats. default is False """

        request = clearly_pb2.CaptureRequest(
            tasks_capture=clearly_pb2.PatternFilter(pattern=pattern or '.',
                                                    negate=negate),
            workers_capture=clearly_pb2.PatternFilter(pattern=workers or '.',
                                                      negate=negate_workers),
        )
        try:
            for realtime in self._stub.capture_realtime(request):
                if realtime.HasField('task'):
                    ClearlyClient._display_task(realtime.task, params, success, error)
                elif realtime.HasField('worker'):
                    ClearlyClient._display_worker(realtime.worker, stats)
                else:
                    print('unknown event:', realtime)
                    break
        except KeyboardInterrupt:
            pass