Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I program, therefore I am.


devel / comp.lang.python / Re: Logging

SubjectAuthor
* LoggingBaran Gökçekli
`* Re: LoggingStefan Ram
 +- Re: LoggingStefan Ram
 +- Re: LoggingCameron Simpson
 `- Re: LoggingThomas Passin

1
Logging

<5fb80174-1266-49f4-813f-6b1546ef8a74n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20408&group=comp.lang.python#20408

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:620a:4884:b0:6fb:c38e:27bf with SMTP id ea4-20020a05620a488400b006fbc38e27bfmr8779106qkb.351.1668854662150;
Sat, 19 Nov 2022 02:44:22 -0800 (PST)
X-Received: by 2002:a9d:373:0:b0:659:73c9:8497 with SMTP id
106-20020a9d0373000000b0065973c98497mr5442589otv.341.1668854661807; Sat, 19
Nov 2022 02:44:21 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Sat, 19 Nov 2022 02:44:21 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=194.27.50.203; posting-account=D8SQNAoAAABV_iR19gAcXiVesQu1VQ_y
NNTP-Posting-Host: 194.27.50.203
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5fb80174-1266-49f4-813f-6b1546ef8a74n@googlegroups.com>
Subject: Logging
From: baran200...@gmail.com (Baran Gökçekli)
Injection-Date: Sat, 19 Nov 2022 10:44:22 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1699
 by: Baran Gökçekli - Sat, 19 Nov 2022 10:44 UTC

How can I solve this question?

There is a module called ‘logging’ to
employ logging facility in Python.

import logging

logging. info('Just a normal message' )

Logging.warning('Not fatal but still noted')

logging.error('There is something wrong')

You are expected to implement logging
feature to an existing code which uses the
function below.

def my_ugly_debug(s, level=0):

pre_text = [ "INFO",
"WARNING",
"ERROR"
]

print(f"{pre_text[level]}: {s}")
You are not allowed to make changes in my_ugly_debug, so find another way.


Re: Logging

<solution-20221119120637@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20409&group=comp.lang.python#20409

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Logging
Date: 19 Nov 2022 11:08:57 GMT
Organization: Stefan Ram
Lines: 16
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <solution-20221119120637@ram.dialup.fu-berlin.de>
References: <5fb80174-1266-49f4-813f-6b1546ef8a74n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de lSetOUHYRntnnxYBzfJG2AiGb6Uui/iudCBX8n7W3PEyfF
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 19 Nov 2022 11:08 UTC

<baran200167@gmail.com> writes:
>You are expected to implement logging feature to an existing
>code which uses the function below.
>def my_ugly_debug(s, level=0):
> pre_text = [ "INFO",
> "WARNING",
> "ERROR"
> ]
> print(f"{pre_text[level]}: {s}")
>You are not allowed to make changes in my_ugly_debug, so find another way.

If found a solution that is even more ugly than your
function. I was just about to post it here, but then
remembered about the "no homework" rule. Bummer!

Re: Logging

<logging-20221119124314@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20410&group=comp.lang.python#20410

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Logging
Date: 19 Nov 2022 11:46:39 GMT
Organization: Stefan Ram
Lines: 27
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <logging-20221119124314@ram.dialup.fu-berlin.de>
References: <5fb80174-1266-49f4-813f-6b1546ef8a74n@googlegroups.com> <solution-20221119120637@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 1dgs4eWwRh5Cuxet8vTI4wlPywrCc8D92yXxMUmkCoPdUp
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 19 Nov 2022 11:46 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>If found a solution that is even more ugly than your
>function. I was just about to post it here, but then
>remembered about the "no homework" rule. Bummer!

I tampered with "sys.stdout" to intercept the "print" calls
and redirect them to logging when they start with a tag,
otherwise they would be printed as usual. So then

print( "normal printing" )
my_ugly_debug( "A", level=0 )
my_ugly_debug( "A", level=1 )
my_ugly_debug( "A", level=2 )

would print

normal printing
WARNING:root:WARNING: A
ERROR:root:ERROR: A

plus some additional empty lines (one would need a bit
more work to clean that up). Another possibility would
be to redefine "print". If decorators, functions, or
classes around the definition of "my_ugly_debug" were
allowed, things could be handled a bit more cleanly.

Re: Logging

<mailman.1007.1668896890.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20416&group=comp.lang.python#20416

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs...@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: Logging
Date: Sun, 20 Nov 2022 09:27:58 +1100
Lines: 30
Message-ID: <mailman.1007.1668896890.20444.python-list@python.org>
References: <solution-20221119120637@ram.dialup.fu-berlin.de>
<Y3lYbq02qX977zLu@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
X-Trace: news.uni-berlin.de f8QyeIYgRkv2Zj8O3/rPtA4SQ++QtciI5IjUrZFkw28w==
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'ram': 0.07; 'writes:':
0.09; 'cheers,': 0.11; 'log': 0.12; 'cameron': 0.16;
'from:addr:cs': 0.16; 'from:addr:cskk.id.au': 0.16;
'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net':
0.16; 'received:13.237': 0.16; 'received:13.237.201': 0.16;
'received:13.237.201.189': 0.16; 'received:cskk.id.au': 0.16;
'received:id.au': 0.16; 'received:mail.cskk.id.au': 0.16;
'simpson': 0.16; 'wrote:': 0.16; 'uses': 0.19; 'calls': 0.19;
'implement': 0.19; 'to:addr:python-list': 0.20; 'code': 0.23;
'stefan': 0.26; 'suspect': 0.26; 'function': 0.27; 'etc': 0.28;
'asked': 0.29; 'header:User-Agent:1': 0.30; 'modify': 0.31;
'official': 0.32; 'here,': 0.32; 'but': 0.32; 'there': 0.33;
'header:In-Reply-To:1': 0.34; 'received:au': 0.35; 'those': 0.36;
'changes': 0.39; 'use': 0.39; 'level.': 0.40; 'skip:m 20': 0.63;
'received:13': 0.64; 'your': 0.64; 'received:userid': 0.66;
'etc,': 0.69; 'took': 0.69; 'addition': 0.71; 'calls.': 0.84;
'inclined': 0.84; 'mapped': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <solution-20221119120637@ram.dialup.fu-berlin.de>
User-Agent: Mutt/2.2.7 (2022-08-07)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <Y3lYbq02qX977zLu@cskk.homeip.net>
X-Mailman-Original-References: <solution-20221119120637@ram.dialup.fu-berlin.de>
 by: Cameron Simpson - Sat, 19 Nov 2022 22:27 UTC

On 19Nov2022 11:08, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
><baran200167@gmail.com> writes:
>>You are expected to implement logging feature to an existing
>>code which uses the function below. [...]
>>You are not allowed to make changes in my_ugly_debug, so find another
>>way.
>
> If found a solution that is even more ugly than your
> function. I was just about to post it here, but then
> remembered about the "no homework" rule. Bummer!

I suspect that the OP is just being asked to modify existing code which
calls my_ugly_debug to use more conventional logging calls.

Baran, in addition to the various info(), warning() etc logging calls
there is a log() logging call which accepts a log level (the warning()
etc calls basicly call this with their own logging level).

I would be inclined to write a my_better_debug(s,level=0) function which
took those existing levels (0,1,2) and mapped them to the official
logging levels logging.INFO, logging.WARNING etc, and then called
logging.log() with the official level.

Then adjust the calling code to call your new function.

The alternative is to just replace every calling function which uses
my_ugly_debug() to directly call a logging.whatever() call.

Cheers,
Cameron Simpson <cs@cskk.id.au>

Re: Logging

<mailman.1009.1668900397.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20419&group=comp.lang.python#20419

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Logging
Date: Sat, 19 Nov 2022 18:26:25 -0500
Lines: 35
Message-ID: <mailman.1009.1668900397.20444.python-list@python.org>
References: <solution-20221119120637@ram.dialup.fu-berlin.de>
<Y3lYbq02qX977zLu@cskk.homeip.net>
<6ba20661-6487-4071-0e87-1f7c369049cf@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de hGT2xkqiHu/muc9M0Mw/Kg1ij8unS20wKYjKjnmJHIDw==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=PlpDIidq;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.019
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'ram': 0.07; 'writes:':
0.09; 'cheers,': 0.11; 'log': 0.12; 'cameron': 0.16;
'received:10.0.0': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'simpson': 0.16; 'wrote:': 0.16;
'uses': 0.19; 'calls': 0.19; 'implement': 0.19; 'pm,': 0.19;
'to:addr:python-list': 0.20; 'maybe': 0.22; 'way.': 0.22; 'code':
0.23; 'stefan': 0.26; 'suspect': 0.26; 'function': 0.27; '>>>':
0.28; 'etc': 0.28; 'asked': 0.29; 'header:User-Agent:1': 0.30;
'modify': 0.31; 'official': 0.32; 'here,': 0.32; 'received:10.0':
0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'there':
0.33; 'header:In-Reply-To:1': 0.34; 'those': 0.36; 'changes':
0.39; 'use': 0.39; 'level.': 0.40; 'skip:m 20': 0.63; 'your':
0.64; 'header:Received:6': 0.67; 'received:64': 0.67; 'etc,':
0.69; 'took': 0.69; 'addition': 0.71; 'calls.': 0.84; 'inclined':
0.84; 'mapped': 0.84
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1668900386; a=rsa-sha256;
cv=none;
b=e/FbrlUvMCnq/QIgumgzCIr+pq/OTG1DcapWgcJNUePBG/hBl2Lr2quyAy95pfAMpAxl6P
S861POQJqseck1IaDLs+EKZphvn3Oy2IgBAZlLSNSxU9j523MKKYYTfglebCknjaSkbzag
kQLkpkpjD6WXeZorbcVMOLLWKhYAWgjOWURlJU5fhiDldwmoBhbUrd88lNKUfNthyECzDB
WG01lXUgYbiR7ZQLEWrqCNrqlpVawSAVJQVXyzNa8emqcCwShCR7lL+/dK6eD3NtrN0ANc
ro1xl01IzfQXYpax+E4255ppFrXMuwbMm684t8yYnbtIOZGsZxuIRWbSVpspaA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1668900386;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=Reo0GGuLUe1ric8qY+vXYFNStastIlL3gryxF5n7RTo=;
b=Kkwzcyb2W8MCXCYj9DjlThdC1f8Z3FkhgCcjCnBTshQRtvaqMJPLBWSuptAtkTF6cZHTyP
jch+a/opwCtCV+wcW+S4PtnG8Z6kWbOG+BMz4xl8apxSG39amgkTpK8FyxiswK+gozD3Ri
4y+A9NlGVYeZdE5KIwgKNf3NLich2ecjXMklXNTQRB1Y7ti/KaTvTz9Ta4GsHnMEDLs3/1
31lT4OZatoKVXSfe35xJWSSFaVd2JQIAQt4r8fduwGSwd+VpNZ6AgGv0Iy9fhrHMOREAC2
rLKMt2obnGuA+Ri/p/j1/HWJ1rpBr5+EuizlMfWmThuHWGTGxSuRukzVAV1Mbg==
ARC-Authentication-Results: i=1; rspamd-65567d767-hlph2;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Attack-Descriptive: 0f6782a95f6c9498_1668900386726_4064031762
X-MC-Loop-Signature: 1668900386726:748712468
X-MC-Ingress-Time: 1668900386725
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1668900386;
bh=Reo0GGuLUe1ric8qY+vXYFNStastIlL3gryxF5n7RTo=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=PlpDIidqK+BEohCqzpfrRB5ZRO1uBZhbdYVh+F0RN9QNJ1k6qfgwNE+ahAvElWI06
sHz32y/dlH3w0hP8AgCAQn62riv50S036yvbJ1F/GLwsExqxzLKOZ7EiNjVHofy50Q
kqEVdu5Tc1SNpRtn44UliGsNDcLuQowxKCwqSMQLTfR0sZdPZMRxzQzfDn5iFFjq0M
763/P4fcHZjJZJm4lJQeKd61jDKHnsfXiGoI8S4Krig80uQ4HuDpzwDvnirBhljrOB
g7ZRJIElHYYp2V+qdoPViqYxiDm6PY0Fl29jh9+NMpQkFKSk7CgbSXW+VvEndsZgs+
d1lW1HkcJvC4g==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.5.0
Content-Language: en-US
In-Reply-To: <Y3lYbq02qX977zLu@cskk.homeip.net>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <6ba20661-6487-4071-0e87-1f7c369049cf@tompassin.net>
X-Mailman-Original-References: <solution-20221119120637@ram.dialup.fu-berlin.de>
<Y3lYbq02qX977zLu@cskk.homeip.net>
 by: Thomas Passin - Sat, 19 Nov 2022 23:26 UTC

On 11/19/2022 5:27 PM, Cameron Simpson wrote:
> On 19Nov2022 11:08, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>> <baran200167@gmail.com> writes:
>>> You are expected to implement logging feature to an existing
>>> code which uses the function below. [...]
>>> You are not allowed to make changes in my_ugly_debug, so find another
>>> way.
>>
>>  If found a solution that is even more ugly than your
>>  function. I was just about to post it here, but then
>>  remembered about the "no homework" rule. Bummer!
>
> I suspect that the OP is just being asked to modify existing code which
> calls my_ugly_debug to use more conventional logging calls.
>
> Baran, in addition to the various info(), warning() etc logging calls
> there is a log() logging call which accepts a log level (the warning()
> etc calls basicly call this with their own logging level).
>
> I would be inclined to write a my_better_debug(s,level=0) function which
> took those existing levels (0,1,2) and mapped them to the official
> logging levels logging.INFO, logging.WARNING etc, and then called
> logging.log() with the official level.
>
> Then adjust the calling code to call your new function.
>
> The alternative is to just replace every calling function which uses
> my_ugly_debug() to directly call a logging.whatever() call.

Maybe a place for a decorator...

> Cheers,
> Cameron Simpson <cs@cskk.id.au>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor