How can I log exception errors to disk of a systemd service?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have written below systemd service that runs the flask app on gunicorn following a tutorial.
I am able to see access logs in /var/log/nginx/ but not log of error happening in the python flask app!
How can I log errors to disk of a systemd service?



$ cat /etc/systemd/system/gunicorn.service                                          [Unit]
Description=gunicorn daemon for /var/www/html/start_backend.py
After=network.target

[Service]
PermissionsStartOnly = true
User=ciasto
Group=www-data
RuntimeDirectory=gunicorn
WorkingDirectory=/var/www/html/
ExecStartPre = /bin/chown -R pi:www-data /var/www/html/
Environment="APP_SETTINGS=production"
Environment="DB_USER=username"
Environment="DB_PWD=password"
Environment="DB_HOST="ceres.local"
ExecStart=/usr/bin/env gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 start_backend:web_app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


To get exception error logs I added below two lines:



StandardOutput=file:/var/log/gunicorn/log1.log
StandardError=file:/var/log/gunicorn/log2.log


I restarted the gunicorn service than visited the URL to throw the exception error, check the path where I expect log to come . But I see nothing



sudo systemctl status  gunicorn                                 ● gunicorn.service - gunicorn daemon for /var/www/html/start_backend.py
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-03 22:42:31 IST; 1min 9s ago
Process: 3944 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 3947 ExecStartPre=/bin/chown -R ciasto:www-data /var/www/html/ (code=exited, status=0/SU Main PID: 3950 (gunicorn)
CGroup: /system.slice/gunicorn.service
├─3950 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3965 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3966 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3967 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 └─3968 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4
Jan 03 22:43:34 ceres env[3950]: db.connect()
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: self._state.set_connection(self._connect())
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: return mysql.connect(db=self.database, **self.connect_paraJan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/__Jan 03 22:43:34 ceres env[3950]: return Connection(*args, **kwargs)
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/coJan 03 22:43:34 ceres env[3950]: super(Connection, self).__init__(*args, **kwargs2)
Jan 03 22:43:34 ceres env[3950]: TypeError: connect() argument 1 must be string, not None
ciasto@ceres:/etc/systemd/system $ cd /var/log/gunicorn ciasto@ceres:/var/log/gunicorn $ ll
total 0
ciasto@ceres:/var/log/gunicorn $









share|improve this question

























  • Did you also do a systemctl daemon-reload after editing the service configuration file?

    – Lucas Werkmeister
    Jan 7 at 12:56











  • Yes I did, because we get a message in terminal to run the command you mentioned if systemd unit is modified.

    – Ciasto piekarz
    Jan 7 at 13:00











  • What's your systemd version?

    – nebuler
    Jan 7 at 21:12











  • systemd 232 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

    – Ciasto piekarz
    Jan 8 at 9:05











  • why and where is this log coming from when I enter journalctl --unit=gunicorn.service -n 100 --no-pager in terminal ?

    – Ciasto piekarz
    Jan 8 at 12:27


















0















I have written below systemd service that runs the flask app on gunicorn following a tutorial.
I am able to see access logs in /var/log/nginx/ but not log of error happening in the python flask app!
How can I log errors to disk of a systemd service?



$ cat /etc/systemd/system/gunicorn.service                                          [Unit]
Description=gunicorn daemon for /var/www/html/start_backend.py
After=network.target

[Service]
PermissionsStartOnly = true
User=ciasto
Group=www-data
RuntimeDirectory=gunicorn
WorkingDirectory=/var/www/html/
ExecStartPre = /bin/chown -R pi:www-data /var/www/html/
Environment="APP_SETTINGS=production"
Environment="DB_USER=username"
Environment="DB_PWD=password"
Environment="DB_HOST="ceres.local"
ExecStart=/usr/bin/env gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 start_backend:web_app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


To get exception error logs I added below two lines:



StandardOutput=file:/var/log/gunicorn/log1.log
StandardError=file:/var/log/gunicorn/log2.log


I restarted the gunicorn service than visited the URL to throw the exception error, check the path where I expect log to come . But I see nothing



sudo systemctl status  gunicorn                                 ● gunicorn.service - gunicorn daemon for /var/www/html/start_backend.py
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-03 22:42:31 IST; 1min 9s ago
Process: 3944 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 3947 ExecStartPre=/bin/chown -R ciasto:www-data /var/www/html/ (code=exited, status=0/SU Main PID: 3950 (gunicorn)
CGroup: /system.slice/gunicorn.service
├─3950 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3965 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3966 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3967 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 └─3968 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4
Jan 03 22:43:34 ceres env[3950]: db.connect()
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: self._state.set_connection(self._connect())
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: return mysql.connect(db=self.database, **self.connect_paraJan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/__Jan 03 22:43:34 ceres env[3950]: return Connection(*args, **kwargs)
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/coJan 03 22:43:34 ceres env[3950]: super(Connection, self).__init__(*args, **kwargs2)
Jan 03 22:43:34 ceres env[3950]: TypeError: connect() argument 1 must be string, not None
ciasto@ceres:/etc/systemd/system $ cd /var/log/gunicorn ciasto@ceres:/var/log/gunicorn $ ll
total 0
ciasto@ceres:/var/log/gunicorn $









share|improve this question

























  • Did you also do a systemctl daemon-reload after editing the service configuration file?

    – Lucas Werkmeister
    Jan 7 at 12:56











  • Yes I did, because we get a message in terminal to run the command you mentioned if systemd unit is modified.

    – Ciasto piekarz
    Jan 7 at 13:00











  • What's your systemd version?

    – nebuler
    Jan 7 at 21:12











  • systemd 232 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

    – Ciasto piekarz
    Jan 8 at 9:05











  • why and where is this log coming from when I enter journalctl --unit=gunicorn.service -n 100 --no-pager in terminal ?

    – Ciasto piekarz
    Jan 8 at 12:27














0












0








0








I have written below systemd service that runs the flask app on gunicorn following a tutorial.
I am able to see access logs in /var/log/nginx/ but not log of error happening in the python flask app!
How can I log errors to disk of a systemd service?



$ cat /etc/systemd/system/gunicorn.service                                          [Unit]
Description=gunicorn daemon for /var/www/html/start_backend.py
After=network.target

[Service]
PermissionsStartOnly = true
User=ciasto
Group=www-data
RuntimeDirectory=gunicorn
WorkingDirectory=/var/www/html/
ExecStartPre = /bin/chown -R pi:www-data /var/www/html/
Environment="APP_SETTINGS=production"
Environment="DB_USER=username"
Environment="DB_PWD=password"
Environment="DB_HOST="ceres.local"
ExecStart=/usr/bin/env gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 start_backend:web_app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


To get exception error logs I added below two lines:



StandardOutput=file:/var/log/gunicorn/log1.log
StandardError=file:/var/log/gunicorn/log2.log


I restarted the gunicorn service than visited the URL to throw the exception error, check the path where I expect log to come . But I see nothing



sudo systemctl status  gunicorn                                 ● gunicorn.service - gunicorn daemon for /var/www/html/start_backend.py
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-03 22:42:31 IST; 1min 9s ago
Process: 3944 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 3947 ExecStartPre=/bin/chown -R ciasto:www-data /var/www/html/ (code=exited, status=0/SU Main PID: 3950 (gunicorn)
CGroup: /system.slice/gunicorn.service
├─3950 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3965 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3966 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3967 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 └─3968 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4
Jan 03 22:43:34 ceres env[3950]: db.connect()
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: self._state.set_connection(self._connect())
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: return mysql.connect(db=self.database, **self.connect_paraJan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/__Jan 03 22:43:34 ceres env[3950]: return Connection(*args, **kwargs)
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/coJan 03 22:43:34 ceres env[3950]: super(Connection, self).__init__(*args, **kwargs2)
Jan 03 22:43:34 ceres env[3950]: TypeError: connect() argument 1 must be string, not None
ciasto@ceres:/etc/systemd/system $ cd /var/log/gunicorn ciasto@ceres:/var/log/gunicorn $ ll
total 0
ciasto@ceres:/var/log/gunicorn $









share|improve this question
















I have written below systemd service that runs the flask app on gunicorn following a tutorial.
I am able to see access logs in /var/log/nginx/ but not log of error happening in the python flask app!
How can I log errors to disk of a systemd service?



$ cat /etc/systemd/system/gunicorn.service                                          [Unit]
Description=gunicorn daemon for /var/www/html/start_backend.py
After=network.target

[Service]
PermissionsStartOnly = true
User=ciasto
Group=www-data
RuntimeDirectory=gunicorn
WorkingDirectory=/var/www/html/
ExecStartPre = /bin/chown -R pi:www-data /var/www/html/
Environment="APP_SETTINGS=production"
Environment="DB_USER=username"
Environment="DB_PWD=password"
Environment="DB_HOST="ceres.local"
ExecStart=/usr/bin/env gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 start_backend:web_app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


To get exception error logs I added below two lines:



StandardOutput=file:/var/log/gunicorn/log1.log
StandardError=file:/var/log/gunicorn/log2.log


I restarted the gunicorn service than visited the URL to throw the exception error, check the path where I expect log to come . But I see nothing



sudo systemctl status  gunicorn                                 ● gunicorn.service - gunicorn daemon for /var/www/html/start_backend.py
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-01-03 22:42:31 IST; 1min 9s ago
Process: 3944 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 3947 ExecStartPre=/bin/chown -R ciasto:www-data /var/www/html/ (code=exited, status=0/SU Main PID: 3950 (gunicorn)
CGroup: /system.slice/gunicorn.service
├─3950 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3965 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3966 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 ├─3967 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 └─3968 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4
Jan 03 22:43:34 ceres env[3950]: db.connect()
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: self._state.set_connection(self._connect())
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]: return mysql.connect(db=self.database, **self.connect_paraJan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/__Jan 03 22:43:34 ceres env[3950]: return Connection(*args, **kwargs)
Jan 03 22:43:34 ceres env[3950]: File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/coJan 03 22:43:34 ceres env[3950]: super(Connection, self).__init__(*args, **kwargs2)
Jan 03 22:43:34 ceres env[3950]: TypeError: connect() argument 1 must be string, not None
ciasto@ceres:/etc/systemd/system $ cd /var/log/gunicorn ciasto@ceres:/var/log/gunicorn $ ll
total 0
ciasto@ceres:/var/log/gunicorn $






gunicorn raspbian systemd exception-logging nginx-log






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 17:20







Ciasto piekarz

















asked Jan 3 at 16:26









Ciasto piekarzCiasto piekarz

2,44643599




2,44643599













  • Did you also do a systemctl daemon-reload after editing the service configuration file?

    – Lucas Werkmeister
    Jan 7 at 12:56











  • Yes I did, because we get a message in terminal to run the command you mentioned if systemd unit is modified.

    – Ciasto piekarz
    Jan 7 at 13:00











  • What's your systemd version?

    – nebuler
    Jan 7 at 21:12











  • systemd 232 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

    – Ciasto piekarz
    Jan 8 at 9:05











  • why and where is this log coming from when I enter journalctl --unit=gunicorn.service -n 100 --no-pager in terminal ?

    – Ciasto piekarz
    Jan 8 at 12:27



















  • Did you also do a systemctl daemon-reload after editing the service configuration file?

    – Lucas Werkmeister
    Jan 7 at 12:56











  • Yes I did, because we get a message in terminal to run the command you mentioned if systemd unit is modified.

    – Ciasto piekarz
    Jan 7 at 13:00











  • What's your systemd version?

    – nebuler
    Jan 7 at 21:12











  • systemd 232 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

    – Ciasto piekarz
    Jan 8 at 9:05











  • why and where is this log coming from when I enter journalctl --unit=gunicorn.service -n 100 --no-pager in terminal ?

    – Ciasto piekarz
    Jan 8 at 12:27

















Did you also do a systemctl daemon-reload after editing the service configuration file?

– Lucas Werkmeister
Jan 7 at 12:56





Did you also do a systemctl daemon-reload after editing the service configuration file?

– Lucas Werkmeister
Jan 7 at 12:56













Yes I did, because we get a message in terminal to run the command you mentioned if systemd unit is modified.

– Ciasto piekarz
Jan 7 at 13:00





Yes I did, because we get a message in terminal to run the command you mentioned if systemd unit is modified.

– Ciasto piekarz
Jan 7 at 13:00













What's your systemd version?

– nebuler
Jan 7 at 21:12





What's your systemd version?

– nebuler
Jan 7 at 21:12













systemd 232 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

– Ciasto piekarz
Jan 8 at 9:05





systemd 232 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

– Ciasto piekarz
Jan 8 at 9:05













why and where is this log coming from when I enter journalctl --unit=gunicorn.service -n 100 --no-pager in terminal ?

– Ciasto piekarz
Jan 8 at 12:27





why and where is this log coming from when I enter journalctl --unit=gunicorn.service -n 100 --no-pager in terminal ?

– Ciasto piekarz
Jan 8 at 12:27












0






active

oldest

votes












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026184%2fhow-can-i-log-exception-errors-to-disk-of-a-systemd-service%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026184%2fhow-can-i-log-exception-errors-to-disk-of-a-systemd-service%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]