I'm using the standard python (2.5.2) logging module, specifically the RotatingFileHandler
, on a linux system. My application supports both a command-line interface and a web-service interface. I would like to have both write to the same log file. However, when the log file gets rotated, the new file has 644
permissions and is owned by the web server user which prevents the command-line user from writing to it. Can I specify that new log files should be group-writable in the logging configuration or during logging initialization?
I have looked into the mode
setting (r
/w
/a
), but it doesn't seem to support any file permissions.
Python Logging Handler The log handler is the component that effectively writes/displays a log: Display it in the console (via StreamHandler), in a file (via FileHandler), or even by sending you an email via SMTPHandler, etc. Each log handler has 2 important fields: A formatter which adds context information to a log.
Logging is a means of tracking events that happen when some software runs. Logging is important for software developing, debugging, and running. If you don't have any logging record and your program crashes, there are very few chances that you detect the cause of the problem.
Logger : This is the class whose objects will be used in the application code directly to call the functions. LogRecord : Loggers automatically create LogRecord objects that have all the information related to the event being logged, like the name of the logger, the function, the line number, the message, and more.
Here is a slightly better solution. this overrides the _open method that is used. setting the umask before creating then returning it back to what it was.
class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler): def _open(self): prevumask=os.umask(0o002) #os.fdopen(os.open('/path/to/file', os.O_WRONLY, 0600)) rtv=logging.handlers.RotatingFileHandler._open(self) os.umask(prevumask) return rtv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With