<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def beacon(config):
    '''
    Read the log file and return match whole string

    .. code-block:: yaml

        beacons:
            log:
              - file: <path>
              - tags:
                  <tag>:
                    regex: <pattern>

    .. note::

        regex matching is based on the `re`_ module

    .. _re: https://docs.python.org/3.6/library/re.html#regular-expression-syntax

    The defined tag is added to the beacon event tag.
    This is not the tag in the log.

    .. code-block:: yaml

        beacons:
            log:
              - file: /var/log/messages #path to log.
              - tags:
                  goodbye/world: # tag added to beacon event tag.
                    regex: .*good-bye.* # match good-bye string anywhere in the log entry.

    '''
    _config = {}
    list(map(_config.update, config))

    ret = []

    if 'file' not in _config:
        event = SKEL.copy()
        event['tag'] = 'global'
        event['error'] = 'file not defined in config'
        ret.append(event)
        return ret

    with salt.utils.files.fopen(_config['file'], 'r') as fp_:
        loc = __context__.get(LOC_KEY, 0)
        if loc == 0:
            fp_.seek(0, 2)
            __context__[LOC_KEY] = fp_.tell()
            return ret

        fp_.seek(0, 2)
        __context__[LOC_KEY] = fp_.tell()
        fp_.seek(loc)

        txt = fp_.read()
        log.info('txt %s', txt)

        d = {}
        for tag in _config.get('tags', {}):
            if 'regex' not in _config['tags'][tag]:
                continue
            if not _config['tags'][tag]['regex']:
                continue
            try:
                d[tag] = re.compile(r'{0}'.format(_config['tags'][tag]['regex']))
            except Exception as e:
                event = SKEL.copy()
                event['tag'] = tag
                event['error'] = 'bad regex'
                ret.append(event)

        for line in txt.splitlines():
            for tag, reg in d.items():
                try:
                    m = reg.match(line)
                    if m:
                        event = SKEL.copy()
                        event['tag'] = tag
                        event['raw'] = line
                        event['match'] = 'yes'
                        ret.append(event)
                except Exception:
                    event = SKEL.copy()
                    event['tag'] = tag
                    event['error'] = 'bad match'
                    ret.append(event)
    return ret