-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing logging from production builds #26
Comments
This can be configured on the Google closure level. In your cljs compiler config: :closure-defines {goog.DEBUG false
goog.debug.LOGGING_ENABLED false} |
shadow-cljs by default will set |
In that case I'm assuming the Google closure library introduced some breaking changes... Would be good to look into that so we can update our docs. |
I don't see any relevant changes in google closure... this is still in there goog.log.ENABLED = goog.define('goog.log.ENABLED', goog.debug.LOGGING_ENABLED); and every logging call is guarded by We'll have to start with a minimal reproduction of the issue. @rome-user if you could help with that that would be really appreciated. Set up a small repo with only a dependency on glogi, configuration for a cljs build tool, and a single namespace with some logging calls, with instructions on how to compile and run. |
In my case, I am successfully getting DCE with the following modification to (defn- log-expr [form level keyvals]
(let [keyvals-map (apply array-map keyvals)
formatter (::formatter keyvals-map 'identity)]
`(when ~(with-meta 'goog.debug.LOGGING_ENABLED {:tag 'boolean})
(log ~(::logger keyvals-map (str *ns*))
~level
(~formatter ~(-> keyvals-map
(dissoc ::logger)
(assoc :line (:line (meta form)))))
~(:exception keyvals-map))))) But with the original |
Are you seeing logs in your console/stdout or not? |
A PR for further minimizing what we emit when logging is disabled is certainly welcome! |
Logs are not being printed. But in the compiled JS file I can see the strings that would be logged if I had e.g. installed the console logger. Basically, the data structures we use for logging do not get DCE'd unless I modify I am currently going to set up a small shadow-cljs project demonstrating this. Then I will upload the repo so you can take a look |
@plexus Sorry for taking a long time. Here is the repository https://github.com/rome-user/glogi-demo |
Sorry for misunderstanding your issue. In that case the behavior you are seeing is to be expected with the current implementation. A patch to elide logging code when LOGGING_ENABLED is false would be more than welcome! |
Fixes lambdaisland#26. This allows code from macros like trace, debug, etc. to be removed by GCC when the user has the compiler constant goog.debug.LOGGING_ENABLED set to false.
In release builds I am noticing trace-level and debug-level log messages that I do not want in the compiled JS file. Mostly to save space because my code has a lot of trace-level and debug-level logs for development purposes.
I have taken a quick look at the macros like
trace
anddebug
. They ultimately return forms invoking a privatelog-expr
function. Would it be possible to offer an option to disable logging entirely? This could be done within the logging macros themselves, or introducing closure constantlambdaisland.glogi/enabled
then wrapping the body oflog-expr
like so.which either goes away entirely or becomes
(do stuff)
under advanced optimizations.The text was updated successfully, but these errors were encountered: