12 Given the function $f(x)=\ln x-a x$, where $a>0, g(x)=f(x)+$ $f^{\prime}(x)$.
(1) If when $1 \leqslant x \leqslant \mathrm{e}$, the maximum value of the function $f(x)$ is -4, find the expression of the function $f(x)$;
(2) Find the range of values for $a$ such that the function $g(x)$ is monotonic on the interval $(0,+\infty)$.
12 (1) Since $f^{\prime}(x)=\frac{1}{x}-a$, $f(x)$ is monotonically increasing in $\left(0, \frac{1}{a}\right)$ and monotonically decreasing in $\left(\frac{1}{a},+\infty\right)$, so $f(x)$ reaches its maximum value when $x=\frac{1}{a}$.
(1) When $0 < a < 1$, $f(x)_{\text {max }}=f(1)=-4$, solving this gives $a=4$, which does not meet the condition;
(2) When $1 \leqslant \frac{1}{a} \leqslant \mathrm{e}$, i.e., $\frac{1}{\mathrm{e}} \leqslant a \leqslant 1$, $f(x)_{\text {max }}=f\left(\frac{1}{a}\right)=-4$, solving this gives $a=\mathrm{e}^{3}>1$ (discard);
(3) When $\frac{1}{a}>\mathrm{e}$, i.e., $0 < a < \frac{1}{\mathrm{e}}$, $f(x)_{\text {max }}=f(\mathrm{e})=-4$, solving this gives $a=\frac{1}{\mathrm{e}}+1 > \frac{1}{\mathrm{e}}$ (discard).
In summary, $f(x)=\ln x-4 x$.
(2) $g(x)=\ln x-a x+\frac{1}{x}-a$,
$$
g^{\prime}(x)=\frac{1}{x}-a-\frac{1}{x^{2}}=-\left(\frac{1}{x}-\frac{1}{2}\right)^{2}+\frac{1}{4}-a .
$$
(1) When $a \geqslant \frac{1}{4}$, $g^{\prime}(x) \leqslant 0$, and only when $x=2$, $g^{\prime}(x)=0$, so $g(x)$ is monotonically decreasing in $(0,+\infty)$;
(2) When $0 < a < \frac{1}{4}$, 
$$
\begin{array}{l}
\frac{1}{x} \in\left(0, \frac{1}{2}-\sqrt{\frac{1}{4}-a}\right) \text {, } g^{\prime}(x)<0 ; \\
\frac{1}{x} \in\left(\frac{1}{2}-\sqrt{\frac{1}{4}-a}, \frac{1}{2}+\sqrt{\frac{1}{4}-a}\right) \text {, } g^{\prime}(x)>0 ; \\
\frac{1}{x} \in\left(\frac{1}{2}+\sqrt{\frac{1}{4}-a},+\infty\right) \text {, } g^{\prime}(x)<0 .
\end{array}
$$

Therefore, $g(x)$ is not monotonic in $(0,+\infty)$.
In summary, the range of values for $a$ is $\left[\frac{1}{4},+\infty\right)$.