473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

logging.py: mutiple system users writing to same file gettingpermission errors.

An a redhat box I have root, apache and other normal users run code
that uses the logging module to write to the same log file. Since
umasks are set to 2 or 022 this gets permission errors.

I have fixed my issue by patching the logging code everywhere there is
an open for write with:
try:
old_umask = os.umask(0)
# open for write here
finally:
os.umask(old_umask)

Is there a better way to solve this issue?
Are there any security problems with this solution other than the log
file not being protected?
Dec 6 '07 #1
3 2904
On Dec 6, 6:35 pm, evenrik <even...@gmail.comwrote:
An a redhat box I have root, apache and other normal users run code
that uses theloggingmodule to write to the same log file. Since
umasks are set to 2 or 022 this gets permission errors.

I have fixed my issue by patching theloggingcode everywhere there is
an open for write with:
try:
old_umask = os.umask(0)
# open for write here
finally:
os.umask(old_umask)

Is there a better way to solve this issue?
Are there any security problems with this solution other than the log
file not being protected?
Multiple processes writing to the same log file may step on each
other's toes: logging contains thread synchronisation code but no
protection against multiple processes accessing the same resource. The
best solution would be to log from all processes to a SocketHandler,
and then have a socket receiver process write the logs to file. This
effectively serialises access to the log file. An example is given in
the logging docs, see

http://docs.python.org/lib/network-logging.html

Of course, you can have the receiver process run under a uid of your
choosing which has the appropriate permissions to write to the log
file.

Regards,

Vinay Sajip
Dec 7 '07 #2
On Dec 7, 12:46 pm, Vinay Sajip <vinay_sa...@yahoo.co.ukwrote:
On Dec 6, 6:35 pm, evenrik <even...@gmail.comwrote:
An a redhat box I have root, apache and other normal users run code
that uses theloggingmodule to write to the same log file. Since
umasks are set to 2 or 022 this gets permission errors.
I have fixed my issue by patching theloggingcode everywhere there is
an open for write with:
try:
old_umask = os.umask(0)
# open for write here
finally:
os.umask(old_umask)
Is there a better way to solve this issue?
Are there any security problems with this solution other than the log
file not being protected?

Multiple processes writing to the same log file may step on each
other's toes: logging contains thread synchronisation code but no
protection against multiple processes accessing the same resource. The
best solution would be to log from all processes to a SocketHandler,
and then have a socket receiver process write the logs to file. This
effectively serialises access to the log file. An example is given in
the logging docs, see

http://docs.python.org/lib/network-logging.html

Of course, you can have the receiver process run under a uid of your
choosing which has the appropriate permissions to write to the log
file.

Regards,

Vinay Sajip
Thank you for the warning about multiple processes. We decided to try
creating a DBHandler to write the logs to PostgeSQL.
Dec 10 '07 #3
On Dec 10, 8:34 pm, evenrik <even...@gmail.comwrote:
On Dec 7, 12:46 pm, Vinay Sajip <vinay_sa...@yahoo.co.ukwrote:
On Dec 6, 6:35 pm, evenrik <even...@gmail.comwrote:
An a redhat box I have root, apache and other normal users run code
that uses theloggingmodule to write to the same log file. Since
umasks are set to 2 or 022 this gets permission errors.
I have fixed my issue by patching theloggingcode everywhere there is
an open for write with:
try:
old_umask = os.umask(0)
# open for write here
finally:
os.umask(old_umask)
Is there a better way to solve this issue?
Are there any security problems with this solution other than the log
file not being protected?
Multiple processes writing to the same log file may step on each
other's toes:loggingcontains thread synchronisation code but no
protection against multiple processes accessing the same resource. The
best solution would be to log from all processes to a SocketHandler,
and then have a socket receiver process write the logs to file. This
effectively serialises access to the log file. An example is given in
theloggingdocs, see
http://docs.python.org/lib/network-logging.html
Of course, you can have the receiver process run under a uid of your
choosing which has the appropriate permissions to write to the log
file.
Regards,
Vinay Sajip

Thank you for the warning about multiple processes. We decided to try
creating a DBHandler to write the logs to PostgeSQL.
Okay. In case you're interested - the original distribution of the
logging package (before it became part of Python) is at
http://www.red-dove.com/python_logging.html and some of the test
scripts, which are in the tarball available from that page, contain an
example database handler (in test script log_test14.py).

Best regards,

Vinay Sajip
Dec 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: JT | last post by:
i have a text file that is used as a logfile for easier debugging. i am using the OpenTextFile method to write to this file. this method exists inside a logging function that can be called from...
16
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
1
by: ramA | last post by:
I would like to log specific web user requests and other specific actions to a file in XML format to analyze site usage and track users.I would appreciate it if anyone can suggest or point me to...
8
by: A.M | last post by:
Hi, What would be the best approach to log different items (SQL, Exceptions, Security, ...) I have a simple Logging function that adds log string to the end of a text file. Is there any...
7
by: Leo Breebaart | last post by:
I have another question where I am not so much looking for a solution but rather hoping to get some feedback on *which* solutions people here consider good Pythonic ways to approach a issue. ...
3
by: nicholas.petrella | last post by:
I am currently trying to use the python logging system as a core enterprise level logging solution for our development and production environments. The rotating file handler seems to be what I...
10
by: jaleel | last post by:
Hi , i would like to reopen the issue in the post http://www.gamedev.net/community/forums/topic.asp?topic_id=418791. My scenario is like this: 1. A web application is there (being created by...
4
by: Alexandru Mosoi | last post by:
why doesn't logging throw any exception when it should? how do I configure logging to throw exceptions? .... logging.fatal('asdf %d', '123') .... except: .... print 'this line is never...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.