Skip to content

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Aug 31, 2025

Description

This PR implements an approach similar to the one used in warnOnce, but for native console functions such as log, warn, and error.

The idea is to gain control over the warnings being issued and thus create more advanced systems for these logs, such as monitoring them through functions. This can be very useful if three.js is used in general-purpose tools like editors and inspectors.

The function to set a callback for console functions is setConsoleFunction and getConsoleFunction:

The THREE. prefix is ​​also no longer necessary, as it is automatically added in the intermediate function.

THREE.setConsoleFunction( ( type, message ) => {

	console.log( type, message ); 

} ); 

@sunag sunag added this to the r181 milestone Aug 31, 2025
Copy link

github-actions bot commented Aug 31, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.91
79.11
338.17
79.12
-743 B
+17 B
WebGPU 579.37
159.66
577.02
159.51
-2.36 kB
-153 B
WebGPU Nodes 577.98
159.42
575.62
159.27
-2.36 kB
-152 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 470.78
113.9
469.76
113.82
-1.02 kB
-81 B
WebGPU 649.52
175.53
647.26
175.34
-2.26 kB
-193 B
WebGPU Nodes 603.62
164.68
601.37
164.5
-2.25 kB
-173 B

@sunag sunag marked this pull request as ready for review August 31, 2025 02:20
@mrdoob
Copy link
Owner

mrdoob commented Aug 31, 2025

Sounds good to me 👍

@mrdoob
Copy link
Owner

mrdoob commented Aug 31, 2025

Why do we need setConsoleFunction though?

Can't we just do const _console = console; in utils.js?

@sunag
Copy link
Collaborator Author

sunag commented Aug 31, 2025

Why do we need setConsoleFunction though?

This is the interesting part, with setConsoleFunction we can monitor the logs, errors, and warnings generated by three.js rather than globally.

Can't we just do const _console = console; in utils.js?

I didn’t understand the purpose, could you explain it to me?

@mrdoob
Copy link
Owner

mrdoob commented Aug 31, 2025

Ah, I think I understand. With setConsoleFuction you can pass yet another wrapped function from a monitor.

Sounds good sounds good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants