What would be the best function to return the depth fed into a shader as a color and which shader should I put it in

So this is one way to do it:
vertex:

#version 330 core

layout (location = 0) in vec3 pos;
uniform mat4 model;
out float zloc;

void main(){
	gl_Position = model * vec4(pos, 1.0f);
	zloc = pos.z;
]

fragment:

#version 330 core

in float zloc;
out vec4 color;
void main(){
	float revDist = 1 / (1 + tan(clamp(zloc + 1, 0, 1.99999) * 0.39269908169872415480783042290994)); //Value is PI / 8
	color = (revDist, revDist, revDist, 1);
}

What do you mean? It’s not clear what the motivation is behind your question.
Perhaps it would help if you spelled out what you perceive about the above that’s undesirable, or insufficient.

As an aside. You don’t really need zloc at all. Check out gl_FragCoord.z in the GLSL 4.6 Spec.

So what I want is to have depth perceived like it is seen by something with eyes.

What you probably want might be this:

gl_FragCoord.z/gl_FragCoord.w - gives you the depth value in clipspace non normalized.

And this gives you the linearized depth information:

float z_n = 2.0 * (gl_FragCoord.z/gl_FragCoord.w)- 1.0;
linear_depth = (2.0 * nearPlane * farPlane ) / (farPlane + nearPlane - z_n * (farPlane-nearPlane));

afterwards you just need to colorize this:

gl_FragColor = color * vec4(linear_depth , 1.0);

You might wanna also check this post what-does-gl-fragcoord-z-gl-fragcoord-w-represent

Are you refering to the fog effect?