Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4929 > unrolled thread

Re: A suggestion for an easy logger

Started bymcilrain <noah.mcilraith@gmail.com>
First post2011-05-07 17:00 -0700
Last post2011-05-10 18:06 +0800
Articles 10 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Re: A suggestion for an easy logger mcilrain <noah.mcilraith@gmail.com> - 2011-05-07 17:00 -0700
    Re: A suggestion for an easy logger Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-05-07 19:27 -0700
      Re: A suggestion for an easy logger TheSaint <nobody@nowhere.net.no> - 2011-05-08 12:49 +0800
        Re: A suggestion for an easy logger TheSaint <nobody@nowhere.net.no> - 2011-05-08 14:15 +0800
          Re: A suggestion for an easy logger Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-05-08 03:26 -0700
            Re: A suggestion for an easy logger TheSaint <nobody@nowhere.net.no> - 2011-05-08 19:21 +0800
              Re: A suggestion for an easy logger Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-05-08 05:31 -0700
                Re: A suggestion for an easy logger TheSaint <nobody@nowhere.net.no> - 2011-05-09 22:53 +0800
                  Re: A suggestion for an easy logger Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-05-09 09:34 -0700
                    Re: A suggestion for an easy logger TheSaint <nobody@nowhere.net.no> - 2011-05-10 18:06 +0800

#4929 — Re: A suggestion for an easy logger

Frommcilrain <noah.mcilraith@gmail.com>
Date2011-05-07 17:00 -0700
SubjectRe: A suggestion for an easy logger
Message-ID<863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com>
Aside from the fact that it's very Javay, what's wrong with the logging module?

[toc] | [next] | [standalone]


#4933

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-05-07 19:27 -0700
Message-ID<f0ca57e6-e93c-48ce-9291-3efbd44f3c3a@z13g2000yqg.googlegroups.com>
In reply to#4929
On May 8, 1:00 am, mcilrain <noah.mcilra...@gmail.com> wrote:
> Aside from the fact that it's very Javay, what's wrong with theloggingmodule?

It's not especially Java-like. Since you can log using just

import logging

logging.basicConfig(level=logging.DEBUG)
logging.debug('This is %sic, not %s-like - that's FUD', 'Python',
'Java')

it doesn't seem especially Java-like: no factories, Interfaces,
builders, using plain functions etc.

The second line is optional and needed only if you want to log DEBUG
or INFO messages (as the default threshold is WARNING).

Despite other logging libraries claiming to be more Pythonic, they
have pretty much the same concepts as stdlib logging - because those
concepts are tied to logging, not to Java. Call it correlation vs.
causation, or convergent evolution, or what you will.

Regards,

Vinay Sajip

[toc] | [prev] | [next] | [standalone]


#4938

FromTheSaint <nobody@nowhere.net.no>
Date2011-05-08 12:49 +0800
Message-ID<iq57ci$562$1@speranza.aioe.org>
In reply to#4933
Vinay Sajip wrote:

WoW :O , the creator !!

> import logging
> 
> logging.basicConfig(level=logging.DEBUG)

I'm getting there, but the result it's not what I would.
As far as I got to know, it should take to write a configuration file, which 
I still not aware of.
I'd like to just have the 4 conditions mentioned in the first post.
Once I'll get into the dirt I'll try to bring up also the other features 
that logging module gives.

-- 
goto /dev/null

[toc] | [prev] | [next] | [standalone]


#4943

FromTheSaint <nobody@nowhere.net.no>
Date2011-05-08 14:15 +0800
Message-ID<iq5cev$efk$1@speranza.aioe.org>
In reply to#4938
TheSaint wrote:

> I'd like to just have the 4 conditions mentioned in the first post.
> 
OK, my analysis led me to the print() function, which would suffice for 
initial my purposes.
Meanwhile I reading the tutorials, but I couldn't get how to make a 
formatter to suppress or keep the LF(CR) at the end of the statement.

-- 
goto /dev/null

[toc] | [prev] | [next] | [standalone]


#4950

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-05-08 03:26 -0700
Message-ID<06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com>
In reply to#4943
On May 8, 7:15 am, TheSaint <nob...@nowhere.net.no> wrote:

> OK, my analysis led me to the print() function, which would suffice for
> initial my purposes.

The logging HOWTO tells you when to use logging, warnings and print():

http://docs.python.org/howto/logging.html

> Meanwhile I reading the tutorials, but I couldn't get how to make a
> formatter to suppress or keep the LF(CR) at the end of the statement.

For Python 3.2 and later, it's the terminator attribute of the
StreamHandler. See:

http://plumberjack.blogspot.com/2010/10/streamhandlers-newline-terminator-now.html

Unfortunately, for earlier Python versions, you'd need to subclass and
override StreamHandler.emit() to get equivalent functionality :-(

Regards,

Vinay Sajip

[toc] | [prev] | [next] | [standalone]


#4952

FromTheSaint <nobody@nowhere.net.no>
Date2011-05-08 19:21 +0800
Message-ID<iq5ubq$moi$1@speranza.aioe.org>
In reply to#4950
Vinay Sajip wrote:

8<
> For Python 3.2 and later, it's the terminator attribute of the
> StreamHandler. See:
8<
> Unfortunately, for earlier Python versions, you'd need to subclass and
> override StreamHandler.emit() to get equivalent functionality :-(
> 
I'm with 3.2 and willing to stay :)
I was trying
==================================code==================================
>>>logging.basicConfig(format='%(message)s',terminator='',level=logging.DEBUG)                            
>>> logging.debug('here we are')
DEBUG:root:here we are                                                                                     
>>>  
==================================code==================================

First I didn't espect to see much more than my message. I agree that I'm 
very new to the module

Second the will terminator appear only to real stdout, or am I doing 
something incorrect?

Note: some word wrapping doesn't show the python shell correctly.

-- 
goto /dev/null

[toc] | [prev] | [next] | [standalone]


#4954

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-05-08 05:31 -0700
Message-ID<bac2afe8-42e8-4eca-9782-85ef58909c00@k22g2000yqh.googlegroups.com>
In reply to#4952
On May 8, 12:21 pm, TheSaint <nob...@nowhere.net.no> wrote:


> First I didn't espect to see much more than my message. I agree that I'm
> very new to the module

You could do

logging.basicConfig(level=logging.DEBUG, format='%(message)s')

to get just the message.

> Second the will terminator appear only to real stdout, or am I doing
> something incorrect?

The terminator is an attribute on the StreamHandler instance, so works
with whatever stream the handler is using. You can't use basicConfig()
directly, if you want to configure the terminator - instead, use
something like

sh = logging.StreamHandler(sys.stdout)
sh.terminator = ''
logging.getLogger().addHandler(sh)

but be sure to execute this code one time only, or you will get
multiple identical messages for a single logging call.

Regards,

Vinay Sajip

[toc] | [prev] | [next] | [standalone]


#4994

FromTheSaint <nobody@nowhere.net.no>
Date2011-05-09 22:53 +0800
Message-ID<iq8v5o$204$1@speranza.aioe.org>
In reply to#4954
Vinay Sajip wrote:

> logging.basicConfig(level=logging.DEBUG, format='%(message)s')

logging.basicConfig(format='%(message)s', level=logging.DEBUG)

I formulated in the reverse order of arguments, may that cause an 
unpredicted result?

The other points became clearer..

Once again
Thank You

-- 
goto /dev/null

[toc] | [prev] | [next] | [standalone]


#4996

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-05-09 09:34 -0700
Message-ID<7508a36a-5d27-49a7-8572-c9bba3d2c61e@h12g2000pro.googlegroups.com>
In reply to#4994
On May 9, 3:53 pm, TheSaint <nob...@nowhere.net.no> wrote:
> Vinay Sajip wrote:
> >logging.basicConfig(level=logging.DEBUG, format='%(message)s')
>
> logging.basicConfig(format='%(message)s', level=logging.DEBUG)
>
> I formulated in the reverse order of arguments, may that cause an
> unpredicted result?

No, you can pass keyword arguments in any order - that's what makes
them keyword, as opposed to positional, arguments.

Regards,

Vinay Sajip

[toc] | [prev] | [next] | [standalone]


#5063

FromTheSaint <nobody@nowhere.net.no>
Date2011-05-10 18:06 +0800
Message-ID<iqb2mb$6r9$1@speranza.aioe.org>
In reply to#4996
Vinay Sajip wrote:

> No, you can pass keyword arguments in any order - that's what makes
> them keyword, as opposed to positional, arguments.

I getting puzzled :)
==================================code==================================
myself@laptop-~> python
Python 3.2 (r32:88445, Apr 15 2011, 11:09:05) 
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging, sys
>>> logging.basicConfig(level=logging.DEBUG, format='%(message)s')
>>> sh = logging.StreamHandler(sys.stdout)
>>> sh.terminator = ''
>>> logging.getLogger().addHandler(sh)
>>> logging.debug('here we are')
here we are
here we are>>> print(logging.__version__)
0.5.1.2
==================================code==================================

Terminator is removed, but as you stated it's doing double print-out
One more point is, if you'd have the time to look back to one of the first 
posts, that the leading *"DEBUG:root:"* doesn't show :-/
It's reported herein the version of Python and logging module's version.

For my thinking I'd go to look into the code and docs as well, to understand 
what I should do to have my 4 way of logging.
I repeat, I'm very new on using logging module, but I should go in that way, 
it isn't necessary to re-invent the wheel :).
Also I'd like to say that's only for my own learning, which I do as hobby.

-- 
goto /dev/null 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web