473,851 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

logging.py: mutiple system users writing to same file gettingpermissi on 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_um ask)

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 2929
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 theloggingmodul e 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_um ask)

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...@ya hoo.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 theloggingmodul e 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_um ask)
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...@ya hoo.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 theloggingmodul e 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_um ask)
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:loggingcon tains 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
3810
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 anywhere in my ASP. this works great for our development system b/c we have a limited number of users. however, we're unable to use this logging mechanism on live due to concurrency issues. when two users attempt to open and write to the text...
16
2187
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 more experienced loggers can provide me with some ideas as to how to log in a simple yet flexible manner. For instance, I'd like the code to be as uncluttered as possible by Trace statements. As an example of basic logging functionality, I've come...
1
1212
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 any resource on how to do this, especially keeping in mind the issue of mutiple users simultaneously writing to the same log file. Thanks in advance.
8
1700
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 application block for that? Should i do the logging into SQL server table ? Any help would be apprecited,
7
1551
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. The situation is this: I am writing fairly large console scripts in Python. They have quite a few command-line options, which lead to configuration variables that are needed all over the program (e.g. the "--verbose" option alone is used by just...
3
5418
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 am looking for as I want the ability to have control over the number and size of log files that are written out for each of our tools. I have noticed a few problems with this handler and wanted to post here to get your impressions and possibly...
10
1806
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 some other company) 2. We develop the business layer and data access layer.
4
3410
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 printed' .... Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py", line 744, in emit
0
9897
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10670
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10356
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9506
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7906
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5933
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4549
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4143
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.