Override dmLogInfo (SOLVED)

#1

Due to the weak functionality of Defold’s log, I want to implement my log, But how to override dmLogInfo、dmLogError…, and redirect the log from Defold’s internal dmLogInfo to my log window?

1 Like

#2

weak functionality of Defold’s log

What functionality are you missing exactly?

But how to override dmLogInfo、dmLogError…

You’re not supposed to override these functions
You can ofc use NSLog and __android_log yourself to print things from your extension.

redirect the log from Defold’s internal dmLogInfo to my log window

You can’t currently do this right now.

0 Likes

#3

In windows, the log window is only the cmd window, which has no find filter and clear functionality
In mac, the runtime have no log window
image

0 Likes

#4

Right now, I can invoke my log function from my extension, and override lua print from extension, But the internal log of defold engine cannot be redirected to my log window

0 Likes

#5

On macOS you can get the log output by starting the binary from a terminal, like so:

❯ ./Downloads/empty_project.app/Contents/MacOS/empty_project
INFO:DLIB: Log server started on port 55068
INFO:ENGINE: Engine service started on port 8001
INFO:ENGINE: Defold Engine 1.2.151 (e05232d)
INFO:ENGINE: Loading data from: dmanif:/Users/svenandersson/Downloads/empty_project.app/Contents/Resources/game.dmanifest
INFO:ENGINE: Initialised sound device 'default'

But you can still bundle your app, then choose it as a target and “Build and Launch”. This works on all platforms (except HTML5), and you will get the log inside the editor, which is searchable.

1 Like

#6

When you run the app from command line you can pipe the output to another tool:

$ ./game.app/Contents/MacOS/game > ~/my_custom_logger_tool

And then all you need to do is implement your custom logger tool

0 Likes

#7

Can This apply to win32?

0 Likes

#8

Not sure how Win32 handles the console window, but it might be something we should look into, if it doesn’t work?

Yet another way is to connect a socket to the log port that is reported when you start the engine, like this:

❯ telnet 127.0.0.1 55712
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
0 OK
DEBUG:SCRIPT: Touch!
DEBUG:SCRIPT: Touch!
DEBUG:SCRIPT: Touch!
DEBUG:SCRIPT: Touch!

This depends on you knowing the log port though, not sure if it can explicitly be set currently. :thinking:

1 Like

#9

Yes. It’s common practice in terminal windows

0 Likes

#10

I haven’t try it, but I had tried running game from Cygwin, and the log is redirected to Cygwin’s window

2 Likes

#11

I’m adding a feature issue for this, ie making the log port configurable: DEF-3919

Update: This has been pushed and will be available in 1.2.153. (Not 152 which is coming on monday.)

3 Likes

#12

Solved in 1.2.153

1 Like

#13

Short example how to use it;

Set DM_LOG_PORT to a port number and start your game binary like this:

$ DM_LOG_PORT=4632 ./MyGame

Then in another terminal, telnet to localhost and the port you used:

$ telnet localhost 4632
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
0 OK
INFO:DLIB: Log server started on port 4632
INFO:ENGINE: Engine service started on port 8001
INFO:ENGINE: Defold Engine 1.2.153 (XXXXXXX)
INFO:ENGINE: Loading data from: .
INFO:ENGINE: Initialised sound device 'default'

INFO:DLIB: SSDP: Started on address XXX.XXX.XXX.XXX

The output from the telnet call above might be different depending on how soon you connect. You can go all out brave and try something like this and try to connect as soon as possible:

$ DM_LOG_PORT=4632 ./MyGame > /dev/null 2>&1 &; telnet localhost 4632

:stuck_out_tongue:

4 Likes