This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to mask certain string attributes in Java during logging?  RSS feed

Ranch Hand
Posts: 165
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to understand if there is anyway I can mask certain string variables of a class like password, etc which will prevent during logging. Like overriding .toString() method in such way it does not print in logs.

For instance:-

We have a class Employee with following fields:-

During logging like

Here in logging, I'm trying to print the whole object, Employee here and my requirement is it should not print out masked field, password at all and whereas logging of rest of the fields are fine.

Thank you,
Posts: 60199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what happens when you print out an instance of this class? Does it print the password?
What is the toString method like?
Why have you got a password as a field in the first place? Why have you stored the password as a String?
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!