How to exclude credentials in mybatis log ?

168 views
Skip to first unread message

Yusuke Tomimoto

unread,
Jun 24, 2021, 10:11:24 PM6/24/21
to mybatis-user
Hi !

In case of handling some credentials as the following with mybatis,

- PhoneNumber
- Address
- etc ...

How to exclude (or hide, protected) in log of these ?

now
```
2021-06-25 10:41:10.629 DEBUG 12807 --- [nio-8081-exec-6] c.f.k.i.a.ApplicationMapper.register     : ==>  Preparing: INSERT INTO applications( application_id, first_name, last_name, birthday) VALUES ( ?, ?, ?, ? ) 

2021-06-25 10:41:10.639 DEBUG 12807 --- [nio-8081-exec-6] c.f.k.i.a.ApplicationMapper.register     : ==> Parameters: 331f10be-50d1-441b-8adf-1cbb4c5401f3(String), John(String), Doe(String), 19950104(String)
```

expected
```
2021-06-25 10:41:10.629 DEBUG 12807 --- [nio-8081-exec-6] c.f.k.i.a.ApplicationMapper.register     : ==>  Preparing: INSERT INTO applications( application_id, first_name, last_name, birthday) VALUES ( ?, ?, ?, ? ) 

2021-06-25 10:41:10.639 DEBUG 12807 --- [nio-8081-exec-6] c.f.k.i.a.ApplicationMapper.register     : ==> Parameters: 331f10be-50d1-441b-8adf-1cbb4c5401f3(String)[PROTECTED](String), [PROTECTED](String), [PROTECTED](String)
```

Are there some config to resolve this ? 

Guy Rouillier

unread,
Jun 25, 2021, 2:19:06 AM6/25/21
to mybatis-user
I haven't done this myself, but found some discussion on this topic starting here:

https://stackoverflow.com/questions/25277930/mask-sensitive-data-in-logs-with-logback

--
Guy Rouillier
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/e9db7b49-8045-42b1-bfbb-71cef079830en%40googlegroups.com.

Yusuke Tomimoto

unread,
Jun 29, 2021, 10:53:41 PM6/29/21
to mybatis-user
It helps me a lot!

But I wonder if  this problem resolved by option like @Exclude annotation in spring boot.
2021年6月25日金曜日 15:19:06 UTC+9 Guy Rouillier:

Iwao AVE!

unread,
Jun 30, 2021, 3:08:09 PM6/30/21
to mybatis-user
Hello Yusuke,

There is an open feature request.
https://github.com/mybatis/mybatis-3/issues/77

You might be aware, but you can change the log level of that particular statement.
If you use Spring Boot, for example, add the following line to application.properties.
logging.level.(package name).ApplicationMapper.register=INFO

Regards,
Iwao

Yusuke Tomimoto

unread,
Aug 28, 2021, 7:54:02 PM8/28/21
to mybatis-user
Hi Iwao,

Thanks for letting me know.

On this, I solved with your plan.

The issue seems useful,
I'll try to watch it later on.

Tom




2021年7月1日木曜日 4:08:09 UTC+9 Iwao AVE!:
Reply all
Reply to author
Forward
0 new messages