how to set a xbmc setting -or- how to activate debug from python

  Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
solexalex Offline
Skilled Python Coder
Posts: 707
Joined: Jul 2004
Reputation: 6
Post: #1
Hi

It has been a long time since i post here ! I had to slow down xbmc plugin/scripts because I needed more family time...

Anyway, I'm a little bit back, and I need some help. I just thought of something so interesting for developpers, that I'm surprised I can't find anything about it... Maybe I don't know what terms I need to look for in the forum.

I think it could be interesting to activate/deactivate XBMC debug logging from our python scripts/plugins.
So the infos I think about are :
- a variable to get the debug status
- a command to set on/off debug logging (as the XBMC setting does)

I tried to find a solution without any success. Does someone can help me ? Oo
(This post was last modified: 2009-02-09 00:30 by solexalex.)
find quote
Voinage Offline
Banned
Posts: 846
Joined: Mar 2008
Location: England
Post: #2
Try setting it via plugin settings- bool.

Try these:

xbmc.executehttpapi("") with GetLogLevel

xbmc.executehttpapi("") with SetLogLevel
find quote
solexalex Offline
Skilled Python Coder
Posts: 707
Joined: Jul 2004
Reputation: 6
Thumbs Up  yeah
Post: #3
Hi

Thanks a lot !! I searched but did not see it (ok i didn't read all, just trying to find 'debug' word and not 'loglevel' ... :noSmile

It works like a charm, and I think I will propose this as an option in my scripts/plugins in the future.

Here is a sample code for those who need it
Code:
import xbmc
actualloglevel = xbmc.executehttpapi("GetLogLevel").replace("<li>","")
if actualloglevel=="2":
    status = xbmc.executehttpapi("SetLogLevel(1)").replace("<li>","")
elif actualloglevel=="1":
    status = xbmc.executehttpapi("SetLogLevel(0)").replace("<li>","")
elif actualloglevel=="0":
    status = xbmc.executehttpapi("SetLogLevel(2)").replace("<li>","")

if status=="OK":
    print "Previous log level was %s, now switched to %s succesfully !"%(actualloglevel,
                                                                         xbmc.executehttpapi("GetLogLevel").replace("<li>",""))
else:
    print "Previous log level was %s, and I was not able to change it !! (message says '%s')"%(actualloglevel,
                                                                                               status)
find quote
queeup Offline
Posting Freak
Posts: 763
Joined: Feb 2009
Reputation: 16
Post: #4
ea nice one but i can't figure out how can I change to debug level (1) on plugin/script exit.

I use this code on my plugin:
Code:
if xbmcplugin.getSetting("debug") == "true":
    xbmc.log("[PLUGIN] '%s: version %s' initialized!" % (__plugin__, __version__,), xbmc.LOGNOTICE)
    xbmc.executehttpapi('SetLogLevel(3)')

what can I do to revert back debug level on exit?
find quote
rwparris2 Offline
Team-XBMC Python Developer
Posts: 1,333
Joined: Jan 2008
Reputation: 2
Location: US
Post: #5
queeup Wrote:what can I do to revert back debug level on exit?

Just set it back at the end of your plugin?
Code:
originalloglevel = xbmc.executehttpapi("GetLogLevel").replace("<li>","")

#...the rest of your plugin...

xbmc.executehttpapi("SetLogLevel(%s)" % (originalloglevel))
sys.modules.clear()

If you're doing this you'll need to wrap the main part of your plugin in a try/except so you can be sure to set the user's setting back to how they were regardless of anything exiting prematurely.

This of course raises the question of why you would want to change the user's log level?

Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
find quote
queeup Offline
Posting Freak
Posts: 763
Joined: Feb 2009
Reputation: 16
Post: #6
I prefer change Debug level from plugin setting instead of going System settings. It's easy for debugging errors. Your suggestion not working because I'm not using separate modules for this plugin. This is my latest plugin. I need the solve some problems before submit.
http://xbmc.pastebin.com/m153a96b
find quote
solexalex Offline
Skilled Python Coder
Posts: 707
Joined: Jul 2004
Reputation: 6
Post: #7
The answer from rwparris2 is totally what you have to do to set the loglevel to what is was before running....
What's wrong with it ?
find quote
queeup Offline
Posting Freak
Posts: 763
Joined: Feb 2009
Reputation: 16
Post: #8
noting wrong but I can't get it work. I want to revert log level on plugin exit.
find quote
amet Offline
Retired Team-Kodi Member
Posts: 4,087
Joined: Jul 2009
Reputation: 41
Location: Novi Sad / Dubai
Post: #9
queeup Wrote:noting wrong but I can't get it work. I want to revert log level on plugin exit.

PHP Code:
# Constants
__plugin__ 'Current TV'
__author__ 'queeup'
__url__ 'http://code.google.com/p/queeup/'
__date__ '18.10.2009'
__version__ '1.0.0'

# Imports
import os
import re
import sys
import time
import xbmc
import xbmcgui
import xbmcplugin
import urllib

# Debug
originalloglevel xbmc.executehttpapi("GetLogLevel").replace("<li>""")
print 
"Original Log Level : [ %s ]" % (originalloglevel)
time.sleep(2)

xbmc.executehttpapi('SetLogLevel(3)')

newloglevel xbmc.executehttpapi("GetLogLevel").replace("<li>""")
print 
"New Log Level : [ %s ]" % (newloglevel)
time.sleep(2)

xbmc.executehttpapi("SetLogLevel(%s)" % (originalloglevel)) 
loglevel xbmc.executehttpapi("GetLogLevel").replace("<li>""")
print 
"Restored Original Log Level : [ %s ]" % (loglevel)

sys.modules.clear() 

This works, maybe post the whole plugin

Cheers
Zeljko
(This post was last modified: 2009-10-18 21:56 by amet.)
find quote
solexalex Offline
Skilled Python Coder
Posts: 707
Joined: Jul 2004
Reputation: 6
Post: #10
If it is a plugin, it may be because you lose the info between to cycle of the plugin. Look this way.
Or maybe you placed the restoration stuff too late in the plugin....
find quote
queeup Offline
Posting Freak
Posts: 763
Joined: Feb 2009
Reputation: 16
Post: #11
I think my English not enough to explain my situation. Ok after few minutes I release this plugin, then maybe someone help me on this.
find quote
amet Offline
Retired Team-Kodi Member
Posts: 4,087
Joined: Jul 2009
Reputation: 41
Location: Novi Sad / Dubai
Post: #12
queeup Wrote:I think my English not enough to explain my situation. Ok after few minutes I release this plugin, then maybe someone help me on this.

spelling mistake

line 33 in default.py, it should be
PHP Code:
xbmc.executehttpapi('SetLogLevel(3)'

you have it as:

PHP Code:
xbmc.executehttpapi('SettLogLevel(3)'


Zeljko
find quote
queeup Offline
Posting Freak
Posts: 763
Joined: Feb 2009
Reputation: 16
Post: #13
Yea i overlook that thx. Actually I commented out that lines on release Smile
find quote
amet Offline
Retired Team-Kodi Member
Posts: 4,087
Joined: Jul 2009
Reputation: 41
Location: Novi Sad / Dubai
Post: #14
queeup Wrote:Yea i overlook that thx. Actually I commented out that lines on release Smile

I know Smile

I un-commented(sp) it and fixed the spelling, if I enable debug in plugin settings it correctly sets debug level to 3 every time I click on the listitem and back to 1 after it finishes.
find quote
queeup Offline
Posting Freak
Posts: 763
Joined: Feb 2009
Reputation: 16
Post: #15
Quote:if I enable debug in plugin settings it correctly sets debug level to 3 every time I click on the listitem and back to 1 after it finishes
Yes I ask this question because of this situation. I need to revert back to debug level 1 just once on the plugin exit. Bahh never mind. It's not important actually Smile
find quote
Post Reply