# 如何删除管理员日志

**URL:** https://meta.discourse.org/t/how-to-remove-admin-logs/80185
**Category:** Support
**Created:** [2018年二月9日 16:31 UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185 "2018-02-09T16:31:13Z")
**Posts on this page:** 1
**Showing post:** 15

<div class="post-metadata">

### Author: ![yoda\_mtfbwu](https://avatars.discourse-cdn.com/v4/letter/y/46a35a/32.png) [@yoda\_mtfbwu](https://meta.discourse.org/u/yoda_mtfbwu)
#### Post date: [2023年十一月14日 18:36 UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/15 "2023-11-14T18:36:42Z")

</div>

您可以使用 rails 控制台来完成此操作，但这样做也很危险。所以，如果我没记错的话，它会是这样的：

> cd /var/discourse

> sudo ./launcher enter app

> rails c

现在您已进入控制台，删除所有工作人员操作/管理员日志的一个选项是使用此方法：

> [@How to clean staff action logs?](https://meta.discourse.org/t/how-to-clean-staff-action-logs/51305/7?u=yoda_mtfbwu):
>
> OK. This is solved via UserHistory.destroy\_all.

但是，这会删除所有内容，这可能不是您想要的。您可能希望限制时间范围或调查某些操作。

例如：  
`UserHistory.where(action: 17, acting_user_id: 5)`

这将返回由 ID 为 5 的用户删除的所有帖子。

或者

`UserHistory.where(action: 17, post_id: 15643)`

这将返回有关谁删除了 ID 为 15643 的帖子的信息。

有关表字段和操作 ID 的列表，请参阅[此文件](https://github.com/discourse/discourse/blob/main/app/models/user_history.rb)：

```plaintext
# == Schema Information
#
# Table name: user_histories
#
# id :integer not null, primary key
# action :integer not null
# acting_user_id :integer
# target_user_id :integer
# details :text
# created_at :datetime not null
# updated_at :datetime not null
# context :string
# ip_address :string
# email :string
# subject :text
# previous_value :text
# new_value :text
# topic_id :integer
# admin_only :boolean default(FALSE)
# post_id :integer
# custom_type :string
# category_id :integer
#
# Indexes
#
# index_user_histories_on_acting_user_id_and_action_and_id (acting_user_id,action,id)
# index_user_histories_on_action_and_id (action,id)
# index_user_histories_on_category_id (category_id)
# index_user_histories_on_subject_and_id (subject,id)
# index_user_histories_on_target_user_id_and_id (target_user_id,id)
# index_user_histories_on_topic_id_and_target_user_id_and_action (topic_id,target_user_id,action)
#

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-remove-admin-logs/80185)._
