80

I would like to develop GNOME Shell extensions and found it's really easy to step into the development process but I still can't figure out how to debug / test my extensions effectively.

Are there any tools for that purpose? Is there any kind of real time console like we have on modern browsers or javascript servers environments?

ks1322
  • 33,961
  • 14
  • 109
  • 164
marcio
  • 10,002
  • 11
  • 54
  • 83

8 Answers8

86

Yes, the real-time console is called "Looking Glass" and can be started by pressing Alt+F2 and typing lg at the prompt.

More info: https://live.gnome.org/GnomeShell/LookingGlass

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • 1
    Just a small doubt about the lookingGlass: I included `global.log('hello world');` inside a loop in my extension but nothing got logged in the console. Can't the extensions log messages programatically? – marcio Dec 08 '11 at 15:09
  • 1
    I've already got the answer. It logs properly but you have to reload the gnome shell environment after any update in the scripts (Alt+F2 and type `r`). – marcio Dec 09 '11 at 11:10
  • Do you know why lg is not working from command-line??!!! working with alt+f2 but not from terminal! – Pipo May 17 '17 at 08:40
  • It's not an executable that you can invoke from the command line. It's specific to GNOME shell. – ptomato May 17 '17 at 11:55
  • 1
    I'm having the same problem as @marcio, extension log messages don't show up in lg, but I've already restarted the shell. How can I print a message in a gnome shell extension and then see it?? – Paul Oct 07 '18 at 16:51
  • Why not open a new question for that? Few people will see it here. – ptomato Oct 07 '18 at 18:27
  • @Paul and @marcio: I had the same problem. Just open a terminal and type `journalctl -f`. After this you will see every log (like `global.log('Test');`)), errors and so on in the terminal. – mhellmeier Mar 06 '19 at 23:36
  • 1
    How do you see source code line numbers for the errors? – SO_fix_the_vote_sorting_bug Apr 25 '19 at 22:05
49

On Fedora 20 (and probably any new linux distro) you can use that command:

journalctl /usr/bin/gnome-session -f -o cat

It constantly (-f) prints errors generated by gnome-session in terminal window. I prefer -o cat flag as it shows full messages without timestaps.

On Fedora 22, I believe, it was replaced with:

journalctl /usr/bin/gnome-shell -f -o cat
jsnjack
  • 2,630
  • 2
  • 21
  • 21
20

Looking Glass is great. If you need a straight console, though, you can get one, but not through LG, at least not as of 3.6.

If you pop open a terminal and type gnome-shell --replace, gnome-shell will run from there, replacing the running instance, and global log output will thereafter appear in that console.

You can test it with Looking Glass by doing Alt-F2 lg, and thenglobal.log("foo") in the "Evaluator" tab.

Geoff
  • 465
  • 3
  • 5
  • 1
    When I cancelled gnome-shell after using the approach, everything froze except for my mouse. I had to hard restart my machine to get it working again. – EndangeredMassa Jul 21 '13 at 02:15
  • 5
    That's because you killed your only instance of gnome-shell. Instead of killing it with `C-c` when you're done, hit `C-z` to suspend it. Then type `bg` into the console (you may not see what you are typing when typing this command) and then gnome-shell will run in the background. Next, run `disown ` to detach the process from the terminal window, after which you can safely close the terminal window. – sharat87 May 22 '14 at 04:36
  • This is dangerous command, I tried and my gnome-shell was restart from zero and now I cant load any of my extensions. – lesimoes Jul 03 '22 at 14:59
  • @lesimoes It's not a thing you want to run in a Wayland world. There you need to restart the session, no way around it. (This answer predates Wayland.) – FeRD Aug 12 '23 at 08:08
8

I prefer reading ~/.xsession-errors and ~/.cache/gdm/session.log files for more detail. Some of the error messages might have a relation with other exceptions or errors.

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
The_Cute_Hedgehog
  • 1,280
  • 13
  • 22
7

The other answers didn't really work for me while developing my own extension. What did however was:

journalctl /usr/lib/gnome-session/gnome-session-binary -f -o cat 

If you want to declutter the output to just see your app, you can use:

journalctl /usr/lib/gnome-session/gnome-session-binary -f -o cat | grep [myAppId]

If you also want to access non error logs using the above method above you can use:

global.log('[myAppId]', valueToLog);

If you don't know the correct path to your gnome session you can also use:

journalctl -f | grep gnome-session

Why it was not working is probably because of my gnome-session-binary path was different, which might be related to a newer version of gnome being installed.

hugo der hungrige
  • 12,382
  • 9
  • 57
  • 84
4

I can't comment on other answers yet, so thought I'd add - however late it may be:

  • For comment 2 of Geoff's answer, just restart the shell via alt+f2 - then r and enter, when that happens - the terminal-run session will end automatically (at least on Debian).

  • I'd recommend jsnjack's answer for general debugging, which works with Debian Jessy as well; probably want to sudo that though. It'll show gnome errors, as well as global.log() messages in whichever terminal you run it in.

If anything, this provides a more complete reference for me - as I've come across this page more than once when referencing info I don't keep fresh in my memory.

Rik
  • 676
  • 7
  • 11
3

Anjuta Dev-Studio is a great tool for working with gnome-shell extensions; it comes equipped with a debugger, GUI designer, version control, and more. There's even a guided tutorial for using Anjuta with gnome-shell extension projects over on gnome's wiki-pages

ILMostro_7
  • 1,422
  • 20
  • 28
  • How does the debugger work? Anjuta doesn't even run the extension in any intuitive fashion, it only prints errors. And the wiki link says nothing about Anjuta except that it exists and to recommend _not_ using it! – SO_fix_the_vote_sorting_bug Apr 27 '19 at 10:34
  • Not sure if the page had changed. You can check other relevant pages for working with the debugger in anjuta; e.g. https://developer.gnome.org/anjuta-manual/stable/debug-tips.html.en – ILMostro_7 Apr 29 '19 at 19:58
3

We are developing a emacs package aimed at gnome-shell extension development here: https://github.com/paperwm/gnome-shell-mode

It's still in "beta" (dec. 2017), but its already very useful.

Features

  • Autocompletion (muuuch better than what looking glass provides)
  • Eval of line, selection, current function, buffer (optionally pasting the result into the buffer in a comment)
  • Highlight of error when evaling
  • Documentation lookup helper
  • Helper to reload the module you're working on without restarting gnome-shell
olejorgenb
  • 1,203
  • 14
  • 25