Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python library for sending/managing usage statistics

Recall those applications that provide the option to "Send usage statistics to help improve X" during the installation? I presume it collects certain patterns of usage and sends it back to the server. Back at the server, there may be some sort of mining going on.

Is there a Python library to do this .. at least from the client part? (other than manually having to code it up using urllib, for instance)

like image 748
Sridhar Ratnakumar Avatar asked Oct 27 '25 06:10

Sridhar Ratnakumar


1 Answers

Sending and receiving logging events across a network

From the docs:

import logging, logging.handlers

rootLogger = logging.getLogger('')
rootLogger.setLevel(logging.DEBUG)
socketHandler = logging.handlers.SocketHandler('localhost',
                    logging.handlers.DEFAULT_TCP_LOGGING_PORT)
# don't bother with a formatter, since a socket handler sends the event as
# an unformatted pickle
rootLogger.addHandler(socketHandler)

# Now, we can log to the root logger, or any other logger. First the root...
logging.info('Jackdaws love my big sphinx of quartz.')
# ...

You can also find there the code for receiving end.

In your case it might be more appropriate to use logging.handlers.DatagramHandler on a non-root logger e.g., logging.getLogger('usage').

like image 131
jfs Avatar answered Oct 28 '25 21:10

jfs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!