FWIW the problem in node is that goog.global is not assigned correctly.
In goog/base.js it is assigned to goog.global = this; but this in node it the current Module instance and not the usual window. module.console does not exist so is not assigned correctly. This works differently in development since the nodejs bootstrap explicitly loads the code with global as this [1]. This will not be done in production so the "default" this becomes the module and breaks optimizied code.
I think its fine to just always use the workaround! since it doesn't break anything.
steps to reproduce
Given
deps.edn
{:paths ["."] :deps {org.clojure/clojurescript {:mvn/version "1.10.339" #_#_:git/url "https://github.com/clojure/clojurescript.git" #_#_:sha "6eedd0a08c49f7b0d4dcb30977b2fb38c90577bd"}}}
foo.cljs
(ns foo (:require [goog.log :as glog]) (:import goog.debug.Console)) (def logger (glog/getLogger "app")) (def console (goog.debug.Console.)) (defn workaround! [] (.setConsole goog.debug.Console js/console)) (defn -main [& args] (.setCapturing console true) (.setLevel logger goog.debug.Logger.Level.FINEST) (when args (workaround!)) (glog/error logger "some error")) (set! *main-cli-fn* -main)
When I compile with optimization `none` and run, logging does appear:
$ clj -m cljs.main -v -O none -t node -c foo $ node out/main.js [ 0.002s] [app] some error
When I compile with optimization `simple` (or `advanced`) and run, logging does not appear.
Expected: optimization simple should have no effect on appearance of logging on Node (just like when compiling for the browser).
various (FWIW)
With simple, `goog.debug.Console.console_` ends up being nil as `goog.global['console']` is nil (https://github.com/google/closure-library/blob/master/closure/goog/debug/console.js#L169).
`println` works in both none and simple.
When targetting browser both none and simple show logging.
A workaround is to setConsole: `(.setConsole goog.debug.Console js/console)`