Python logger file permissions
Ubuntu server 16.04.5 LTS
I have a python script which creates log files using the following code:
today = datetime.today()
datem = datetime(today.year, today.month, today.day)
logger = logging.getLogger('processImport')
hdlr = logging.FileHandler('{0}myLog_{1}-{2}-{3}.log'.format(myLogFileLocation, datem.year, datem.month, datem.day))
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
saving a log entry with:
logger.info(logMessage)
I then have a cron job that deletes older log files after a certain period by executing a python file which uses os.remove(fullFilePath)
to delete the file.
However, I am getting a permissions error when this cron job executes.
OSError: [Errno 13] Permission denied: PathToTheFiletheLogFileName.log
When I check the permissions for the file they are set to:
-rw-r--r-- 1 www-data www-data etc etc
What do I need to do to enable the cron job to have permission to delete the log files please?
Thank you.
python logging
add a comment |
Ubuntu server 16.04.5 LTS
I have a python script which creates log files using the following code:
today = datetime.today()
datem = datetime(today.year, today.month, today.day)
logger = logging.getLogger('processImport')
hdlr = logging.FileHandler('{0}myLog_{1}-{2}-{3}.log'.format(myLogFileLocation, datem.year, datem.month, datem.day))
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
saving a log entry with:
logger.info(logMessage)
I then have a cron job that deletes older log files after a certain period by executing a python file which uses os.remove(fullFilePath)
to delete the file.
However, I am getting a permissions error when this cron job executes.
OSError: [Errno 13] Permission denied: PathToTheFiletheLogFileName.log
When I check the permissions for the file they are set to:
-rw-r--r-- 1 www-data www-data etc etc
What do I need to do to enable the cron job to have permission to delete the log files please?
Thank you.
python logging
1
I guess you need (+w
) permissions on the file, and (+x
) on the parent directory.
– Mayank Porwal
Nov 26 '18 at 3:55
add a comment |
Ubuntu server 16.04.5 LTS
I have a python script which creates log files using the following code:
today = datetime.today()
datem = datetime(today.year, today.month, today.day)
logger = logging.getLogger('processImport')
hdlr = logging.FileHandler('{0}myLog_{1}-{2}-{3}.log'.format(myLogFileLocation, datem.year, datem.month, datem.day))
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
saving a log entry with:
logger.info(logMessage)
I then have a cron job that deletes older log files after a certain period by executing a python file which uses os.remove(fullFilePath)
to delete the file.
However, I am getting a permissions error when this cron job executes.
OSError: [Errno 13] Permission denied: PathToTheFiletheLogFileName.log
When I check the permissions for the file they are set to:
-rw-r--r-- 1 www-data www-data etc etc
What do I need to do to enable the cron job to have permission to delete the log files please?
Thank you.
python logging
Ubuntu server 16.04.5 LTS
I have a python script which creates log files using the following code:
today = datetime.today()
datem = datetime(today.year, today.month, today.day)
logger = logging.getLogger('processImport')
hdlr = logging.FileHandler('{0}myLog_{1}-{2}-{3}.log'.format(myLogFileLocation, datem.year, datem.month, datem.day))
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
saving a log entry with:
logger.info(logMessage)
I then have a cron job that deletes older log files after a certain period by executing a python file which uses os.remove(fullFilePath)
to delete the file.
However, I am getting a permissions error when this cron job executes.
OSError: [Errno 13] Permission denied: PathToTheFiletheLogFileName.log
When I check the permissions for the file they are set to:
-rw-r--r-- 1 www-data www-data etc etc
What do I need to do to enable the cron job to have permission to delete the log files please?
Thank you.
python logging
python logging
edited Nov 26 '18 at 4:25
eyllanesc
84k103562
84k103562
asked Nov 26 '18 at 3:51
DougDoug
888
888
1
I guess you need (+w
) permissions on the file, and (+x
) on the parent directory.
– Mayank Porwal
Nov 26 '18 at 3:55
add a comment |
1
I guess you need (+w
) permissions on the file, and (+x
) on the parent directory.
– Mayank Porwal
Nov 26 '18 at 3:55
1
1
I guess you need (
+w
) permissions on the file, and (+x
) on the parent directory.– Mayank Porwal
Nov 26 '18 at 3:55
I guess you need (
+w
) permissions on the file, and (+x
) on the parent directory.– Mayank Porwal
Nov 26 '18 at 3:55
add a comment |
1 Answer
1
active
oldest
votes
There seems to be a write issue permission with the folder. Changing the permission should help.
Try this:
log_dir = '/abs/path/of/directory'
os.chmod(log_dir, 0777)
Let me know how it goes.
Thanks, solved. It was the permissions on the parent folder. I changed these withchmod 777 DirName
directly from terminal rather than with python (I had tried that yesterday and I guess for the same reasons that too had a permissions error).
– Doug
Nov 27 '18 at 3:26
Glad it worked out. Cheers mate!
– Sagar Dawda
Nov 27 '18 at 7:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474579%2fpython-logger-file-permissions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There seems to be a write issue permission with the folder. Changing the permission should help.
Try this:
log_dir = '/abs/path/of/directory'
os.chmod(log_dir, 0777)
Let me know how it goes.
Thanks, solved. It was the permissions on the parent folder. I changed these withchmod 777 DirName
directly from terminal rather than with python (I had tried that yesterday and I guess for the same reasons that too had a permissions error).
– Doug
Nov 27 '18 at 3:26
Glad it worked out. Cheers mate!
– Sagar Dawda
Nov 27 '18 at 7:42
add a comment |
There seems to be a write issue permission with the folder. Changing the permission should help.
Try this:
log_dir = '/abs/path/of/directory'
os.chmod(log_dir, 0777)
Let me know how it goes.
Thanks, solved. It was the permissions on the parent folder. I changed these withchmod 777 DirName
directly from terminal rather than with python (I had tried that yesterday and I guess for the same reasons that too had a permissions error).
– Doug
Nov 27 '18 at 3:26
Glad it worked out. Cheers mate!
– Sagar Dawda
Nov 27 '18 at 7:42
add a comment |
There seems to be a write issue permission with the folder. Changing the permission should help.
Try this:
log_dir = '/abs/path/of/directory'
os.chmod(log_dir, 0777)
Let me know how it goes.
There seems to be a write issue permission with the folder. Changing the permission should help.
Try this:
log_dir = '/abs/path/of/directory'
os.chmod(log_dir, 0777)
Let me know how it goes.
answered Nov 26 '18 at 4:55
Sagar DawdaSagar Dawda
455211
455211
Thanks, solved. It was the permissions on the parent folder. I changed these withchmod 777 DirName
directly from terminal rather than with python (I had tried that yesterday and I guess for the same reasons that too had a permissions error).
– Doug
Nov 27 '18 at 3:26
Glad it worked out. Cheers mate!
– Sagar Dawda
Nov 27 '18 at 7:42
add a comment |
Thanks, solved. It was the permissions on the parent folder. I changed these withchmod 777 DirName
directly from terminal rather than with python (I had tried that yesterday and I guess for the same reasons that too had a permissions error).
– Doug
Nov 27 '18 at 3:26
Glad it worked out. Cheers mate!
– Sagar Dawda
Nov 27 '18 at 7:42
Thanks, solved. It was the permissions on the parent folder. I changed these with
chmod 777 DirName
directly from terminal rather than with python (I had tried that yesterday and I guess for the same reasons that too had a permissions error).– Doug
Nov 27 '18 at 3:26
Thanks, solved. It was the permissions on the parent folder. I changed these with
chmod 777 DirName
directly from terminal rather than with python (I had tried that yesterday and I guess for the same reasons that too had a permissions error).– Doug
Nov 27 '18 at 3:26
Glad it worked out. Cheers mate!
– Sagar Dawda
Nov 27 '18 at 7:42
Glad it worked out. Cheers mate!
– Sagar Dawda
Nov 27 '18 at 7:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474579%2fpython-logger-file-permissions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I guess you need (
+w
) permissions on the file, and (+x
) on the parent directory.– Mayank Porwal
Nov 26 '18 at 3:55