If interest rates are deterministic (i.e. time-dependent but non-ranom), then
\begin{align}
B(t,T) &= \exp\left( - \int_t^T r(s)\mathrm{d}s\right) \\
\Leftrightarrow \int_t^T r(u)\mathrm{d}u &= -\ln B(t,T).
\end{align}
Differentiating both sides with respect to $T$ according to the Leibniz rule yields
\begin{align*}
r(T) &= -\frac{\partial \ln B(t,T)}{\partial T}\\
&= -\frac{1}{B(t,T)} \frac{\partial B(t,T)}{\partial T}.
\end{align*}
The latter line uses the chain rule. Recall that $\frac{\partial B(t,T)}{\partial T}<0$ which gives you positive interest rates. After all, bond prices typically decrease with maturity.
If interest rates are stochastic, the first equation requires a conditional expectation. However, note that by definition, the instantaneous forward rate $f(t,T)$ satisfies
\begin{align*}
f(t,T) &= -\frac{\partial \ln B(t,T)}{\partial T} \\
&=-\frac{1}{B(t,T)}\frac{\partial B(t,T)}{\partial T}.
\end{align*}
The latter equality follows again from the chain rule. The first line allows you to write again
\begin{align*}
B(t,T) = \exp\left(-\int_t^T f(t,s)\mathrm{d}s\right).
\end{align*}
This holds even if interest rates are stochastic. Furthermore, note that $\lim\limits_{T\to t} f(t,T) = r(t)$, which is the instantaneous short rate.