Why you use log to measure metallicity in galaxies? For example, I saw the next expression for matallicity in a paper: $\log(O/H) + 12$.

I understand O/H is the O(Oxygen) to H(Hydrogen) ratio but why is there the number 12? And why the logarithm?
The distribution of metallicities appear to be more evenly spread out in logspace than in linear space. The reason for this can be ascribed to there being no preferred scale for the abundance of a given element; rather they span several orders of magnitude. The same can be said for instance about the distribution of dust grain sizes, the distribution of the mass of dark matter halos, and the distribution of the area of lakes on Earth.

So, if you measure the number of oxygen atoms (or ions) in ten stars, and divide by the number of hydrogen atoms, you may get values like
$$\mathrm{O}/\mathrm{H} = \{0.03,3.5,25,0.003,0.9,0.4,0.09,0.01,8,0.02\}\times10^{-4}.$$
Plotting this in a linear and a logarithmic plot, you see that on a log scale, the values are easier to tell apart:

 

(Another reason, as zibadawa timmy writes in his/her answer, is that taking the log you don't need to write all those $10^x$ factors).

Now why add 12? This factor corresponds to measuring the number of a given atom per $10^{12}$ hydrogen atoms. I've been asking colleagues from students to professor level, and the best answer we can come up with, is that the least abundant elements in the Sun (uranium, rhenium, thorium, …) have abundances of the order of one per $10^{12}$ hydrogen atoms, so adding 12 to $\log(X/\mathrm{H})$ makes all values positive. This angst of negative values, I don't understand, though. Usually, we're okay with minuses. And measuring metallicities in stars or gas of sub-solar metallicity yield negative values anyway. Moreover, the scale was in use even when we had only lower thresholds for uranium and bismuth of $\log(\mathrm{U}/\mathrm{H})+12&lt;0.8$ and $\log(\mathrm{Bi}/\mathrm{H})+12&lt;0.6$, respectively (Grevesse 1969) and didn't know if they were actually smaller.