Python Forum
Avoid third party functions to wrote my python code into system debug-log?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Avoid third party functions to wrote my python code into system debug-log?
#1
I already asked this on stackoverflow, i will here as well.

I'm not sure how exactly to explain this question because my english is no so god. But i will try with the sample source code.

I am on some open-embedded system where system debug-log can be enabled or disabled. If is enabled all events from boot to reboot are written into debug log in /home/root/logs/ folder. So any code which i wrote in my python app is written to this debug log. How to avoid this?

Let me explain with some piece of code.
startStream is my code:
def startStream(myUrl):
    from SomeFolder.SomeApp.SomeFile import PlayStream
    PlayStream(myUrl)
PlayStream isn't my code. it's somewhere on the system:
def PlayStream(url):
    print(url)
    session.PlayService(url)
So as you can see, PlayStream function will write down my url into debug log, but i don't want this. I don't want to people see my links (in this case). Let me explain that SomeFolder.SomeApp.SomeFile import PlayStream is a imaginary import and function name and can be a lot of similar function anywhere across the system.

How to avoid that third party functions/methods from python or from other languages wrote my python stuff into system debug log?
Reply
#2
If anything means for you guys: I have already tried to redirect print which i want to hide from stdout to file or string buffer, but it seems nothing works. Solution form here doesn't work.
https://stackoverflow.com/a/1218951/9157441

For example:
from cStringIO import StringIO # Python3 use: from io import StringIO
import sys
def startStream(myUrl):
    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()
    from SomeFolder.SomeApp.SomeFile import PlayStream
    PlayStream(myUrl)
    
An again in system debug-log:
Output:
15:26:57.0339 { } /usr/lib/python2.7/site-packages/twisted/python/util.py:815 untilConcludes 2022-04-09 15:26:57+0200 [-] playing [b]4097:0:0:0:0:0:0:0:0:0:http%3a//blahblah.net%3a80/a/movie?action=stream&id=0005&hash=qwertzuiop:Eaux Profondes[/b] 15:26:57.0371 [ ] service/servicemp3.cpp:195 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_audiosink created *** 15:26:57.0389 [ ] service/servicemp3.cpp:204 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_videosink created *** 15:26:57.0404 [ ] service/servicemp3.cpp:213 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_subsink created *** 15:26:57.0404 [ ] service/servicemp3.cpp:233 play [eServiceFactoryMP3] ****new play service total services played is 1**** 15:26:57.0408 [ ] service/servicemp3.cpp:725 eServiceMP3 [eServiceMP3] playbin uri=[b]http://blahblah.com:80/a/movie?action=stream&id=0005&hash=qwertzuiop[/b] 15:26:57.0453 [ ] service/servicemp3.cpp:959 start [eServiceMP3] *** starting pipeline ****
Reply
#3
For example if i call servicemp3 to play my url, this the output from servicemp3.cpp in debug-log:

Output:
15:26:57.0339 { } /usr/lib/python2.7/site-packages/twisted/python/util.py:815 untilConcludes 2022-04-09 15:26:57+0200 [-] playing [b]4097:0:0:0:0:0:0:0:0:0:http%3a//blahblah.net%3a80/a/movie?action=stream&id=0005&hash=qwertzuiop:Eaux Profondes[/b] 15:26:57.0371 [ ] service/servicemp3.cpp:195 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_audiosink created *** 15:26:57.0389 [ ] service/servicemp3.cpp:204 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_videosink created *** 15:26:57.0404 [ ] service/servicemp3.cpp:213 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_subsink created *** 15:26:57.0404 [ ] service/servicemp3.cpp:233 play [eServiceFactoryMP3] ****new play service total services played is 1**** 15:26:57.0408 [ ] service/servicemp3.cpp:725 eServiceMP3 [eServiceMP3] playbin uri=[b]http://blahblah.com:80/a/movie?action=stream&id=0005&hash=qwertzuiop[/b] 15:26:57.0453 [ ] service/servicemp3.cpp:959 start [eServiceMP3] *** starting pipeline ****
The same thing is for exteplayer3 or any player.

The point is how to avoid prints from third party apps?

I am so sorry for three posts in a row, but I’m trying to portray my problem the best I can.
Reply
#4
If Python code is logging things with the logging module, you could try to disable it with
import logging
logging.disable(logging.CRITICAL)
Reply
#5
it doesn't work.
Everything is as before.
Reply
#6
It would probably help if you showed real code - looks like there's some C++ library in there (servicemp3.cpp), so perhaps the logging in there needs configuring if, that's even possible.
Reply
#7
Guys, thank you for your interest.

Sadly i can't change anything in C++ code.
i'll try with some 'live' code, but it's complicated and i hope you will understand, because some stuff i do not know explain how works.

For example here is servicemp3.cpp where is 'eServiceReference'.
servicemp3.cpp is compiled to enigma binary, from which i import 'eServiceReference'

from enigma import eServiceReference

def play(self):
url = "http://someurl.com:80/blah.mp4"
service = eServiceReference(4097, 0, url)

# here's playing start:
self.session.nav.playService(service)   
# i am not sure from which above line come, i think from Navigation.py, but it's not need to be imported to work
# https://github.com/openatv/enigma2/blob/7.0/lib/python/Navigation.py
btw, 4097 = gstreamer, 5002 = exteplayer3, etc...

So, after i run this code, debug-log will write:
Output:
15:26:57.0339 { } /usr/lib/python2.7/site-packages/twisted/python/util.py:815 untilConcludes 2022-04-09 15:26:57+0200 [-] playing [b]4097:0:0:0:0:0:0:0:0:0:http%3a//someurl.com%3a80/blah.mp4 15:26:57.0371 [ ] service/servicemp3.cpp:195 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_audiosink created *** 15:26:57.0389 [ ] service/servicemp3.cpp:204 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_videosink created *** 15:26:57.0404 [ ] service/servicemp3.cpp:213 create_gstreamer_sinks [eServiceFactoryMP3] **** dvb_subsink created *** 15:26:57.0404 [ ] service/servicemp3.cpp:233 play [eServiceFactoryMP3] ****new play service total services played is 1**** 15:26:57.0408 [ ] service/servicemp3.cpp:725 eServiceMP3 [eServiceMP3] playbin uri=http://someurl.com:80/blah.mp4 15:26:57.0453 [ ] service/servicemp3.cpp:959 start [eServiceMP3] *** starting pipeline **** ...
I also tried to disable debug (only to show warnning), for 'eServiceReference' after import. Nothing, again the same output.
import logging
logging.getLogger("eServiceReference").setLevel(logging.WARNING)
I also tried to disable debug for 'enigma'. You can guess, nothing of course, again the same output.
import logging
logging.getLogger("enigma").setLevel(logging.WARNING)
So, what else i can try? May i disable debug for function (def play)?
This drives me nuts, because nothing happened whatever i try.
Reply
#8
Something is wrong on my side. I do not know why.
Pls check this out. Let's try to simplify stuff.

main.py
from . dialog import myDialog
import logging
logging.getLogger("dialog").setLevel(logging.WARNING)
myDialog() 
dialog.py
def myDialog():
    print("00000000000000000000000000000000000000000000000000000000000001212121211121")
in debug-log:
Output:
19:59:00.5019 { } /usr/lib/python2.7/site-packages/twisted/python/util.py:815 untilConcludes 2022-04-09 19:59:00+0200 [-] 00000000000000000000000000000000000000000000000000000000000001212121211121
According to this code print can't be written to debug?
So, what i missing here?
Reply
#9
Look at the debug log. Clearly it depends on how the python interpreter was called to execute the code. There is no mention of the twisted module in the code, but it appears in the debug log.
Reply
#10
Yes, that is totally strange.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running 3rd party libs on Steam Deck (Arch Linux) with restricted access metulburr 0 1,874 Jan-07-2023, 10:41 PM
Last Post: metulburr
  pycharm debug help mg24 1 1,042 Nov-18-2022, 05:38 AM
Last Post: deanhystad
  Python debug suddenly got bad ben1122 3 1,112 Sep-03-2022, 06:20 AM
Last Post: ben1122
  How to use a function from third party library? rrowhe4d 2 1,871 Aug-31-2021, 04:30 PM
Last Post: Larz60+
Bug Help Debug please jamesaarr 12 3,881 Jul-28-2021, 11:20 PM
Last Post: Pedroski55
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,662 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Did interpreter 'compile' all import modules(from thrid-party) jamesyuan 10 4,335 Oct-19-2020, 10:49 AM
Last Post: jamesyuan
  Error in Int object is not subscript-able. How to debug this ? yanDvator 1 2,239 Aug-03-2020, 02:28 PM
Last Post: Larz60+
  installing third-party modules shabux 5 3,472 Apr-13-2020, 12:41 AM
Last Post: Larz60+
  How to avoid open and save a url every time I run code davidm 4 2,662 Mar-03-2020, 10:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020