Reputation: 958
Is there a file handler that we can use to change the permissions of the log file created by the Jython script in Linux? The following is the code flow:
I want the file permissions to be changed to 777 for the log file. How do I do it? Is there a Log File Handler that I can utilize for this purpose?
IOError: [Errno 13] Permission denied: '/home/path/....xyz.out'
LOG_FILENAME = str(propertyFile.getProperty("log_file_path"))
logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG)
logging.debug("--Log Message--")
Upvotes: 0
Views: 3358
Reputation: 958
Found out the following solution:
Use stat module on os.chmod to set permissions. The following code sets the permissions to RWX for User, Group and Others. The OR condition takes care of setting it for User, Group and Others individually.
Code:
LOG_FILENAME = str(propertyFile.getProperty("log_file_path"));
logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG);
os.chmod(LOG_FILENAME, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO);
logging.debug("--Log Message--");
Upvotes: 1