I have hit BUG_ON in kernel code. I want to know what went wrong at that time.
BUG_ON will check for the condition and if it is true, it will panic.
Will BUG_ON print the messages in /var/log/messages?
Will it print the value it is checking before panicking?
Yes. From include/asm-generic/bug.h:
Provided your kernel is compiled appropriately,
BUG_ONwill print a message before panicking.