美文网首页
使用filter_parameter_logging过滤敏感日志

使用filter_parameter_logging过滤敏感日志

作者: Kjiang | 来源:发表于2015-11-29 18:48 被阅读245次

在rails的日志打印中,我们经常需要对信息进行日志打印过滤,如密码一类的信息。

下面是正常的日志输出:

Processing UsersController#create (for 127.0.0.1 at 2009-01-02 10:13:13) [POST]
Parameters: {"user"=>{"name"=>"eifion", "password_confirmation"=>"secret", "password"=>"secret"}, "commit"=>"Register", "authenticity_token"=>"9efc03bcc37191d8a6dc3676e2e7890ecdfda0b5"}
User Create (0.5ms)   INSERT INTO "users" ("name", "updated_at", "password_confirmation", "password", "created_at") VALUES('eifion', '2009-01-02 10:13:13', 'secret', 'secret', '2009-01-02 10:13:13')

当我们对password做日志过滤后:

class ApplicationController < ActionController::Base
  filter_parameter_logging "password" 
end

过滤后的日志:

Processing UsersController#create (for 127.0.0.1 at 2009-01-02 11:02:33) [POST]
  Parameters: {"user"=>{"name"=>"susan", "password_confirmation"=>"[FILTERED]", "password"=>"[FILTERED]"}, "commit"=>"Register", "action"=>"create",
  "authenticity_token"=>"9efc03bcc37191d8a6dc3676e2e7890ecdfda0b5", "controller"=>"users"}
    User Create (0.4ms)   INSERT INTO "users" ("name", "updated_at", "password_confirmation", "password", "created_at") VALUES('susan', '2009-01-02 11:02:33', 'verysecret', 'verysecret', '2009-01-02
    11:02:33')

于2015-03-31

相关文章

  • 使用filter_parameter_logging过滤敏感日志

    在rails的日志打印中,我们经常需要对信息进行日志打印过滤,如密码一类的信息。 下面是正常的日志输出: 当我们对...

  • 自定义过滤器 2016.12.17

    记录日志 debug模式下,记录日志出现warning 使用自定义的过滤器 在components下新建一个过滤器...

  • python实现敏感词过滤的几种方法

    1.replace过滤 最简单也是最直接的就是直接循环敏感词,然后使用replace过滤关键词,文章和敏感词少的时...

  • 敏感词过滤器

    使用Decorator模式包装request对象实现敏感字符过滤功能。敏感词包括了:禁用词:反对共产党、色情。。。...

  • 敏感词过滤算法(2)

    去年写过一篇文章,名字叫做《敏感词过滤算法》,介绍了为什么需要敏感词过滤算法?以及使用什么方式来实现的。其中提到三...

  • Logstash Filter配置和注意事项——古氪流技术

    Logstash进行日志采集: 在Logstash进行日志采集的时候需要使用Filter对数据进行过滤,这里可能会...

  • adb logcat使用

    adb logcat过滤某个日志 用代码实现: adb logcat实现 adb logcat过滤多个日志

  • Java实现敏感词过滤 - DFA算法

    Java实现DFA算法进行敏感词过滤 封装工具类如下: 使用前需对敏感词库进行初始化: SensitiveWord...

  • Linux查看日志命令

    查询日志 按行号查看--过滤关键字附近的日志 按日期怎么查呢?按时间段查询的日志 使用more 和less命令 g...

  • logcat过滤等级及特定进程

    有的时候Android studio日志很容易被冲掉,我们可以通过命令行自己灵活过滤日志。 过滤指定pid日志 过...

网友评论

      本文标题:使用filter_parameter_logging过滤敏感日志

      本文链接:https://www.haomeiwen.com/subject/euqjhttx.html