You could try
capture.output(install.packages('package_name','other arguments'),
file = "install.log", append = FALSE,
type = c("output", "message"), split = FALSE)
with type one of the two options output or message
I hope that this gives you already enough information.
At one time I thought I needed both output and message so I extended the function above to HOQCutil::capture.output.both to be able to specify both :
HOQCutil::capture.output.both(install.packages('package_name','other arguments'),
file = "install.log", append = FALSE,
type = "both", split = FALSE)
You can install the package from GitHub with
devtools::install_github("HanOostdijk/HOQCutil")
or just copy the single function from
https://raw.githubusercontent.com/HanOostdijk/HOQCutil/master/R/cap.out.R