You need to create a text layer and apply a source text expression that uses thisComp.layer("XYZ").name or thisComp.layer("XYZ").source.name, depending on what you actually want. If you want to address multiple layers, you would probably use a for() loop and check, if they are active/ visible at a given time. I'm too lazy to fire up AE and write my own code, but a quick web search turned up this:
It has all the basic ingredients, you just need to adapt it.
Hello, I read the code from the link and it seems the code is working. But I'm new in AE and I dont know to put those code inside AE. Do I need to use Visual Studio??