Merge lp:~raharper/curtin/trunk.add-syslog-handler into lp:~curtin-dev/curtin/trunk

Proposed by Ryan Harper
Status: Work in progress
Proposed branch: lp:~raharper/curtin/trunk.add-syslog-handler
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 64 lines (+16/-3)
1 file modified
curtin/log.py (+16/-3)
To merge this branch: bzr merge lp:~raharper/curtin/trunk.add-syslog-handler
Reviewer Review Type Date Requested Status
Scott Moser (community) Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+330914@code.launchpad.net

Description of the change

Always log to syslog

Add a default syslog log handler and always enable.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

Adjust your comment to mention that we are now supporting multiple handlers at once (I think).
And then i approve.

Is there a way to disable the syslog logger? It doesnt look like it. I dont have a reason at the moment to suggest that it needs to be.

review: Approve
Revision history for this message
Ryan Harper (raharper) wrote :

On Tue, Nov 28, 2017 at 9:52 AM, Scott Moser <email address hidden>
wrote:

> Review: Approve
>
> Adjust your comment to mention that we are now supporting multiple
> handlers at once (I think).
> And then i approve.
>
> Is there a way to disable the syslog logger? It doesnt look like it. I
> dont have a reason at the moment to suggest that it needs to be.
>

I want to review it in light of the journal_report logger; I thought this
would have replaced it but the journal reporter was needed separately
and the syslog had some interesting side-effects w.r.t the reporting logger.

I'll mark this WIP

Ryan

>
>
> --
> https://code.launchpad.net/~raharper/curtin/trunk.add-
> syslog-handler/+merge/330914
> You are the owner of lp:~raharper/curtin/trunk.add-syslog-handler.
>

Unmerged revisions

527. By Ryan Harper

log: always write to syslog

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/log.py'
2--- curtin/log.py 2015-08-12 20:58:05 +0000
3+++ curtin/log.py 2017-09-18 14:50:41 +0000
4@@ -16,6 +16,7 @@
5 # along with Curtin. If not, see <http://www.gnu.org/licenses/>.
6
7 import logging
8+import logging.handlers
9
10 # Logging items for easy access
11 getLogger = logging.getLogger
12@@ -29,6 +30,9 @@
13 DEBUG = logging.DEBUG
14 NOTSET = logging.NOTSET
15
16+CURTIN_LOG_FMT = \
17+ "[CURTIN] %(asctime)s - %(filename)s[%(levelname)s]: %(message)s"
18+
19
20 class NullHandler(logging.Handler):
21 def emit(self, record):
22@@ -36,6 +40,9 @@
23
24
25 def basicConfig(**kwargs):
26+ # always log to syslog
27+ syslog = logging.handlers.SysLogHandler(address='/dev/log')
28+ handlers = [syslog]
29 # basically like logging.basicConfig but only output for our logger
30 if kwargs.get('filename'):
31 handler = logging.FileHandler(filename=kwargs['filename'],
32@@ -44,6 +51,7 @@
33 handler = logging.StreamHandler(stream=kwargs['stream'])
34 else:
35 handler = NullHandler()
36+ handlers.append(handler)
37
38 if 'verbosity' in kwargs:
39 level = ((logging.ERROR, logging.INFO, logging.DEBUG)
40@@ -51,9 +59,11 @@
41 else:
42 level = kwargs.get('level', logging.NOTSET)
43
44- handler.setFormatter(logging.Formatter(fmt=kwargs.get('format'),
45- datefmt=kwargs.get('datefmt')))
46- handler.setLevel(level)
47+ fmt = kwargs.get('format', CURTIN_LOG_FMT)
48+ for handler in handlers:
49+ handler.setFormatter(logging.Formatter(fmt=fmt,
50+ datefmt=kwargs.get('datefmt')))
51+ handler.setLevel(level)
52
53 logging.getLogger().setLevel(level)
54
55@@ -63,6 +73,9 @@
56 logger.setLevel(level)
57 logger.addHandler(handler)
58
59+ for h in handlers:
60+ logger.addHandler(h)
61+
62
63 def _getLogger(name='curtin'):
64 return logging.getLogger(name)

Subscribers

People subscribed via source and target branches