Python clear logs

12 Python code examples are found related to " clear logs". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: software.py    From AstroBox with GNU Affero General Public License v3.0 6 votes vote down vote up
def clearLogs(self):
		activeLogFiles = ['astrobox.log', 'serial.log', 'electron.log', 'touch.log']

		logsDir = self._settings.getBaseFolder("logs")

		# first delete all old logs
		for f in os.listdir(logsDir):
			path = os.path.join(logsDir, f)

			if os.path.isfile(path) and f not in activeLogFiles:
				os.unlink(path)

		# then truncate the currently used one
		for f in activeLogFiles:
			path = os.path.join(logsDir,f)
			if os.path.isfile(path):
				with open(path, 'w'):
					pass

		return True 
Example 2
Source File: async.py    From loom with GNU Affero General Public License v3.0 6 votes vote down vote up
def clear_expired_logs():
    import elasticsearch
    import curator
    elasticsearch_host = get_setting('ELASTICSEARCH_HOST')
    elasticsearch_port = get_setting('ELASTICSEARCH_PORT')
    elasticsearch_log_expiration_days = get_setting('ELASTICSEARCH_LOG_EXPIRATION_DAYS')
    client = elasticsearch.Elasticsearch([elasticsearch_host], port=elasticsearch_port)
    ilo = curator.IndexList(client)
    ilo.filter_by_regex(kind='prefix', value='logstash-')
    ilo.filter_by_age(source='name', direction='older', timestring='%Y.%m.%d',
                      unit='days', unit_count=elasticsearch_log_expiration_days)
    delete_indices = curator.DeleteIndices(ilo)
    try:
        delete_indices.do_action()
    except curator.exceptions.NoIndices:
        pass 
Example 3
Source File: instance.py    From singularity-compose with Mozilla Public License 2.0 6 votes vote down vote up
def clear_logs(self):
        """delete logs for an instance, if they exist.
        """
        log_folder = self._get_log_folder()

        for ext in ["out", "err"]:
            logfile = os.path.join(log_folder, "%s.%s" % (self.name, ext.lower()))

            # Use Try/catch to account for not existing.
            try:
                if not self.sudo:
                    self.client._run_command(["rm", logfile], quiet=True)
                    self.client._run_command(["touch", logfile], quiet=True)
                else:
                    self.client._run_command(["sudo", "rm", logfile], quiet=True)
                    self.client._run_command(["sudo", "touch", logfile], quiet=True)
            except:
                pass 
Example 4
Source File: views.py    From rainmap-lite with GNU General Public License v3.0 5 votes vote down vote up
def clear_logs(request):
    """Clear admin activity logs if user has permissions"""

    if not request.user.is_authenticated(): # should be applied to anything under /console
        return redirect('login')

    if request.user.has_perm('admin.delete_logentry'):
        LogEntry.objects.all().filter(user__pk=request.user.id).delete()
        messages.info(request, 'Successfully cleared admin activity logs.', fail_silently=True)
    else:
        messages.warning(request, 'Unable to clear the admin activity logs.', fail_silently=True)

    return redirect('admin:index') 
Example 5
Source File: tasks.py    From fomalhaut-panel with MIT License 5 votes vote down vote up
def do_clear_old_access_logs(expires_day):
    # gridfs 文件的上传时间使用的是utc时间
    utc_expires = datetime.utcnow() - timedelta(days=expires_day)
    # access_log 里面使用的时间是当前时区的时间
    expires = datetime.now() - timedelta(days=expires_day)
    logger.debug(expires)
    # 删除 access_log
    AccessLog.objects(accessed_at__lt=expires).delete()

    # 删除 header 和 body 的 grid_fs 文件
    AccessLogRequest.delete_expired_headers_files(utc_expires)
    AccessLogRequest.delete_expired_body_files(utc_expires)
    AccessLogResponse.delete_expired_headers_files(utc_expires)
    AccessLogResponse.delete_expired_body_files(utc_expires) 
Example 6
Source File: tasks.py    From fomalhaut-panel with MIT License 5 votes vote down vote up
def clear_old_access_logs():
    """
    清理过期的访问日志数据
    :return:
    """
    logger.debug('执行 clear_old_access_logs')
    access_log_keep_days = settings.ACCESS_LOG_KEEP_DAYS
    do_clear_old_access_logs(access_log_keep_days)
    logger.debug('执行 clear_old_access_logs 完成') 
Example 7
Source File: parse_events.py    From SARA with MIT License 5 votes vote down vote up
def clear_logs(logs, target_tags):
    valid_logs = list()
    for log in logs:
        lf = extract_info(log)
        if lf['tag'] in target_tags:
            valid_logs.append(log)
    return valid_logs 
Example 8
Source File: Config.py    From EventMonkey with Apache License 2.0 5 votes vote down vote up
def ClearLogs():
		if os.path.isdir('logs'):
			filelist = glob.glob("logs/*.log")
			for f in filelist:
				open(f, 'w+') 
Example 9
Source File: rtlsdr_helper.py    From scikit-dsp-comm with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def clear_logs(self):
        '''
        Used in Mono FM Receiver example to clear widget logs
        '''
        self.output.clear_output() 
Example 10
Source File: util.py    From byob with GNU General Public License v3.0 5 votes vote down vote up
def clear_system_logs():
    """
    Clear Windows system logs (Application, security, Setup, System)

    """
    try:
        for log in ["application","security","setup","system"]:
            output = powershell("& { [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog(\"%s\")}" % log)
            if output:
                log(output)
    except Exception as e:
        log(e) 
Example 11
Source File: client_config.py    From EasyStorj with MIT License 5 votes vote down vote up
def handle_clear_logs_action(self):
        msgBox = QtGui.QMessageBox(
            QtGui.QMessageBox.Question,
            'Question',
            'Are you sure that you want to clear all logs?',
            (QtGui.QMessageBox.Yes | QtGui.QMessageBox.No))

        result = msgBox.exec_()

        if result == QtGui.QMessageBox.Yes:
            QtGui.QMessageBox.about(
                self,
                'Success',
                'All logs have been successfully cleared!') 
Example 12
Source File: BlenderScene.py    From 3d-dl with MIT License 5 votes vote down vote up
def clear_logs(self):
        """
        Clears the logs of all sampled parameters
        :return: None
        """
        self_dict = vars(self)
        for attr_name in self_dict.keys():
            attr = self_dict[attr_name]
            if hasattr(attr, 'sample_param'):
                attr.clear_log()