Individually Logging All The Layer/Neuron Outputs

I’m interested in exploring the outputs of different layers/attention heads in models like BERT and BART and was wondering if there is any way to log all the individual outputs from different layers and components within those layers so feedforward networks etc. for a piece of input.
Any leads or suggestions on how to do this? The only way I can think of right now is to modify the code myself and add logging everywhere but that is not generalizable across models and I’ll need to do it individually on a case to case basis.