How to dynamically count the hit times of bin in the simulation process

How to dynamically count the hit times of bins in the simulation process, and print it to the log file every time the covergroup sample, i want to know it there some way to solve it rather than see it in the simulation database after the simulation. can anyone help me?