[PATCH 4 of 7] [logging] send logs by default to stdout

Laurent Peuch cortex at worlddomination.be
Fri Sep 20 02:36:14 CEST 2019


On Thu, Sep 05, 2019 at 04:34:21PM +0200, Denis Laxalde wrote:
> Laurent Peuch a écrit :
> > # HG changeset patch
> > # User Laurent Peuch <cortex at worlddomination.be>
> > # Date 1566333946 -7200
> > #      Tue Aug 20 22:45:46 2019 +0200
> > # Node ID b581c9996564877909b47221ce9d8d6f4f35638c
> > # Parent  458f8d85ec5c9b9109f0ad8c878b192e8f88e03b
> > [logging] send logs by default to stdout
> > 
> > Following the move to have commands only working on foreground sending logs to
> > a file by default doesn't make much more sens anymore so send them to stdout by
> > default and add a new option to send them to a file if needed
> > 
> > diff --git a/cubicweb/cwconfig.py b/cubicweb/cwconfig.py
> > --- a/cubicweb/cwconfig.py
> > +++ b/cubicweb/cwconfig.py
> > @@ -626,7 +626,7 @@ this option is set to yes",
> >      cubicweb_appobject_path = set(['entities'])
> >      cube_appobject_path = set(['entities'])
> >  
> > -    def __init__(self, debugmode=False):
> > +    def __init__(self, debugmode=False, log_to_file=False):
> >          if debugmode:
> >              # in python 2.7, DeprecationWarning are not shown anymore by default
> >              filterwarnings('default', category=DeprecationWarning)
> > @@ -634,6 +634,7 @@ this option is set to yes",
> >          self._cubes = None
> >          super(CubicWebNoAppConfiguration, self).__init__()
> >          self.debugmode = debugmode
> > +        self.log_to_file = log_to_file
> >          self.adjust_sys_path()
> >          self.load_defaults()
> >          # will be properly initialized later by _gettext_init
> > @@ -664,12 +665,12 @@ this option is set to yes",
> >              # no logrotate on win32, so use logging rotation facilities
> >              # for now, hard code weekly rotation every sunday, and 52 weeks kept
> >              # idea: make this configurable?
> > -            init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format,
> > +            init_log(not self.log_to_file, syslog, logthreshold, logfile, self.log_format,
> 
> What if "self.log_to_file" is False and "logfile" is not None?

Then if will send the output so syslog.

> Aren't these things doing something similar. In fact, I'd expect
> that if "logfile" is None, logs would go to stdout. Perhaps we
> should make the corresponding configuration option (log-file) unset
> by default if we really want to get rid of this.

I would have done that if it was possible but this behavior is coming
directly from logilab-common: init_log
https://logilab-common.readthedocs.io/en/latest/_modules/logilab/common/logging_ext.html#init_log
is calling get_handler
https://logilab-common.readthedocs.io/en/latest/_modules/logilab/common/logging_ext.html#get_handler
which is the real deal and decide if things goes to stdout or not.

While I'm a bit questionned by the design of logilab.common.logging_ext.init_log
I think that it's really the best strategy to enforce a "log to
stdout" behavior upfront directly in CubicWeb : that avoid breaking
behavior of other softwares that could use it, that prevent from
having a coordinated release between logilab-common and 3.27, we know
for sure that this behavior is enforced and that just the simpliest
thing to do.

> But is this behaviour harmful after all?

I'm not sure if you are talking about not sending things to stdout by
default but instead on a file in /tmp/ for commands that are launched
for debugging but if it's the case I think that:

* it's a big confusing UX problem, you aren't even informed about
  that, it tooks me a lot of time to find out that while reading the
  source code :/
* since we are moving to "no daemon mode" anymore, adopting the
  behavior of sending everything to stdout and let process like
  systemd/equivalent take care of logging makes much more sense to me

-- 

Laurent Peuch -- Bram



More information about the cubicweb-devel mailing list