As part of an exercise (whose eventual purpose is to derive Stirling's approximation), I had to obtain the relation$\int_1^n \frac{t-\lfloor{t\rfloor}}{t}dt = \frac{1}{2}\log{n} + O(1)$ (where $n$ is an integer). I belive I found a way of proving it, but (a) I'm not sure it's correct, and (b) it's rather messy, and I'm fairly certain there is a simpler way of showing that the relation holds. Any suggestions would be appreciated. Anyway, I tried proving it as follows:
For an integer $i$, and for any $0<r<1$ we have: $$ \int_i^{i+1}\frac{t-\lfloor{t\rfloor}}{t}dt = \int_i^{i+1}\frac{t-i}{t}dt=\sum_{k=0}^\infty\int_{i+1-r^k}^{i+1-r^{k+1}}\frac{t-i}{t}dt $$ In each of the elements in the above sum the interval of integration is of length $r^k(1-r)$, and the integrand in that interval is bound by $\frac{1}{i}(1-r^{k+1})$. Thus, the entire sum is bound by: $$ \frac{1-r}{i}\sum_{k=0}^\infty r^k(1-r^{k+1})=\frac{1-r}{i}\left(\frac{1}{1-r}-\frac{r}{1-r^2}\right)=\frac{1}{i(r+1)} $$ Since the above bound holds for all $0<r<1$, then by taking the limit $r\rightarrow1^-$, we see that it must also hold for $r=1$. Thus: $$ \int_1^n \frac{t-\lfloor{t\rfloor}}{t}dt =\sum_{i=1}^{n-1}\int_i^{i+1} \frac{t-\lfloor{t\rfloor}}{t}dt \le \frac{1}{2}\sum_{i=1}^{n-1}\frac{1}{i}=\frac{1}{2}\log{n} + O(1) $$ Where the rightmost equality is obtained by approximating the sum by an integral.
So far, it's correct, but you have only shown an upper bound, you also need a lower bound. It's easier to write
$$\int_{i}^{i+1} \frac{t - \lfloor t\rfloor}{t}\,dt = \frac{1}{2}\int_i^{i+1}\frac{dt}{t} + \int_i^{i+1} \frac{t-\lfloor t\rfloor - \frac{1}{2}}{t}\,dt$$
and then estimate
\begin{align} \biggl\lvert \int_i^{i+1} \frac{t-\lfloor t\rfloor - \frac{1}{2}}{t}\,dt\biggr\rvert &= \biggl\lvert \int_0^{\frac{1}{2}} h\cdot \biggl(\frac{1}{i+\frac{1}{2}+h} - \frac{1}{i + \frac{1}{2} - h}\biggr)\,dh\biggr\rvert\\ &= \int_0^{\frac{1}{2}} \frac{2h^2}{\bigl(i+\frac{1}{2}\bigr)^2 - h^2}\,dh\\ &\leqslant\frac{1}{4} \frac{1}{\bigl(i + \frac{1}{2}\bigr)^2 - \frac{1}{4}}\\ &= \frac{1}{4i(i+1)}, \end{align}
which shows
$$\Biggl\lvert \int_1^n \frac{t-\lfloor t\rfloor}{t}\,dt - \frac{1}{2}\int_1^n \frac{dt}{t}\Biggr\rvert \leqslant \frac{1}{4} \sum_{i = 1}^{n-1} \frac{1}{i(i+1)} = \frac{1}{4} - \frac{1}{4n}.$$
A slightly more conservative estimate, namely
$$\frac{h^2}{\bigl(i + \frac{1}{2}\bigr)^2} < \frac{h^2}{\bigl(i + \frac{1}{2}\bigr)^2 - h^2} < \frac{h^2}{\bigl(i + \frac{1}{2}\bigr)^2 - \frac{1}{4}}$$
for $0 < h < \frac{1}{2}$, gives us
$$\frac{1}{12}\sum_{i = 1}^{n-1} \frac{1}{\bigl(i + \frac{1}{2})^2} < \int_1^n \frac{\frac{1}{2} + \lfloor t\rfloor - t}{t}\,dt < \frac{1}{12}\sum_{i = 1}^{n-1} \frac{1}{i(i+1)} = \frac{1}{12} \biggl(1 - \frac{1}{n}\biggr).$$
With
$$\sum_{i = n}^{\infty} \frac{1}{\bigl(i + \frac{1}{2}\bigr)^2} < \sum_{i = n}^{\infty} \frac{1}{i(i+1)} = \frac{1}{n},$$
we obtain (for $n > 1$, the right inequality becomes an equality for $n = 1$)
$$\frac{\pi^2-8}{24} - \frac{1}{12n} < \int_1^n \frac{\frac{1}{2} + \lfloor t\rfloor - t}{t}\,dt < \frac{1}{12} - \frac{1}{12n}$$
and thus, evaluating the integral exactly,
$$\frac{\pi^2-8}{24} - \frac{1}{12n} < \bigl(n + \tfrac{1}{2}\bigr)\log n - n - \log n! + 1 < \frac{1}{12} - \frac{1}{12n}.$$
After rearranging, this becomes
$$\bigl(n+\tfrac{1}{2}\bigr)\log n - n + \tfrac{11}{12} + \tfrac{1}{12n} < \log n! < \bigl(n + \tfrac{1}{2}\bigr)\log n - n + \tfrac{32-\pi^2}{24} + \tfrac{1}{12n},$$
which, for so little effort, is rather close to Stirling's formula
$$\log n! = \bigl(n + \tfrac{1}{2}\bigr)\log n - n + \log \sqrt{2\pi} + \tfrac{1}{12n} + O(n^{-2}).$$