also, I would say work is quite a bit different than a gym. it's a lot easier to find a new gym than a new job, and it's much less disruptive to your life if you have to do so.
My boss and I have a good enough relationship at work where I'm 1000% confident this wouldn't happen, and if said boss did "perceive" some kind of drop in productivity, their response would be to help me with that rather than turn it into a negative. Indeed, during COVID when I expressed to my boss that I was having a tough time, his immediate response was to ask how he could help and to offer me a couple days off to recharge.
And the reason we have that relationship is specifically because we treat each other as friends that also happen to have a working relationship, rather than letting the work relationship dominate all else.
Not everyone will have that kind of relationship with their boss, but I believe it is something everyone should aspire to rather than immediately rejecting it as even a possibility.
I would absolutely share this with my "work friends" and even my current boss. When one of my previous bosses shared with me that he was having trouble at home with his spouse, it wasn't like he suddenly became a bad boss. If anything, it helped our work because it gave me the opportunity to be more understanding when he seemed more worn out or needed to leave early for the day to go spend time with his family. If he had told me he was struggling with drinking, then I would know that maybe we should go play sports rather than to our weekly happy hour. We build each other up, both inside and outside of work, because that's what friends do, and it has the nice side effect of making our professional careers better, too.
Perhaps I just have had a lucky stream of working on unicorn teams, but I would hate to work at a company where I couldn't share details of my life with the people that I spend 40-60+ hours a week with. Obviously every workplace and relationship is unique and you aren't going to share everything with everybody (I'd share the above details with my current boss but by no means with all of my bosses), but I don't understand this attitude that you shouldn't share anything with anyone that happens to have a common employer.
To me, work is just another facet of our relationship alongside the many other facets, no different than if we had met through volunteering or went to the same gym. I don't share everything with every coworker, just like I don't share everything with every other person that visits my gym. But I also don't shy away from sharing things with someone just because they are my coworker, just like I wouldn't shy away from sharing things with someone just because they also use the same weight set that I do.