<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def logs(environment, opts):
 """Display or follow container logs Usage: datacats logs [--postgres | --solr | --datapusher] [-s NAME] [-tr] [--tail=LINES] [ENVIRONMENT] datacats logs -f [--postgres | --solr | --datapusher] [-s NAME] [-r] [ENVIRONMENT] Options: --datapusher Show logs for datapusher instead of web logs --postgres Show postgres database logs instead of web logs -f --follow Follow logs instead of exiting immediately --solr Show solr search logs instead of web logs -t --timestamps Add timestamps to log lines -s --site=NAME Specify a site for logs if needed [default: primary] --tail=LINES Number of lines to show [default: all] ENVIRONMENT may be an environment name or a path to an environment directory. Default: '.' """

    container = 'web'
    if opts['--solr']:
        container = 'solr'
    if opts['--postgres']:
        container = 'postgres'
    if opts['--datapusher']:
        container = 'datapusher'
    tail = opts['--tail']
    if tail != 'all':
        tail = int(tail)
    l = environment.logs(container, tail, opts['--follow'],
        opts['--timestamps'])
    if not opts['--follow']:
        print l
        return
    try:
        for message in l:
            write(message)
    except KeyboardInterrupt:
        print