<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_output(self, data, args=None, filename=None, pretty=False):
 """Write log data to a single JSON object"""

        if args:
            if not args.sojson:
                return 0
            pretty = args.pretty
        if not filename: filename = args.sojson
        if pretty:
            logstring = json.dumps(
                    data['entries'], indent=2, sort_keys=True,
                    separators=(',', ': '))
        else:
            logstring = json.dumps(data['entries'], sort_keys=True)
        
        with open(str(filename), 'w') as output_file:
            output_file.write(logstring)