• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to generate the unique message id for log message  RSS feed

 
manish gupta
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my client program I want log the message with unique message id. I am using apache log for the log message, but I don't know how to generate the unique message id

Could anyone help me to solve this problem?

thanks in advance
 
A Kesher
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is exactly what you are after but you can use.

java.rmi.server.UID

to create a unique ID.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, if you have one application, write a class where you are sure that only one instance ever exists (avoiding the word "singleton" here) :-)

delegate the responsibility to initialize and increase the id to that class.

write a getter for the id

make sure everyone who needs an unique id only aquires it through the getter method.

hope it helps,
jan
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!