Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Netscape is not a newsreader, and probably never shall be. -- Tom Christiansen


devel / comp.lang.python / from my lab 3

SubjectAuthor
o from my lab 3Stefan Ram

1
from my lab 3

<lab-20230210152355@ram.dialup.fu-berlin.de>

  copy mid

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

  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: from my lab 3
Date: 10 Feb 2023 14:31:11 GMT
Organization: Stefan Ram
Lines: 49
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <lab-20230210152355@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 q3aoLyrrTR/+9LjAjOf41QJrddUGBNVitAysYNzCXMivx2
X-Copyright: (C) Copyright 2023 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 - Fri, 10 Feb 2023 14:31 UTC

main.py

import logging

logging.getLogger().setLevel( logging.DEBUG )

class log_class:
def __init__( self ):
self.depth = 0
def wrap( self, func ):
def wrap( *args, **kwargs ):
self.info( 'starting ' + func.__name__ )
self.depth += 1
result = func( *args, **kwargs )
self.info( 'ending ' + func.__name__ )
self.depth -= 1
return result
return wrap
def info( self, text ):
logging.info( ' ' * self.depth + text )

log = log_class()

@log.wrap
def factorial( n ):
log.info( f'{n = }' )
return n * factorial( n - 1 ) if n else 1

factorial( 2 )

output

INFO:root:starting factorial
INFO:root: n = 2
INFO:root: starting factorial
INFO:root: n = 1
INFO:root: starting factorial
INFO:root: n = 0
INFO:root: ending factorial
INFO:root: ending factorial
INFO:root: ending factorial

previous "from my lab" posts

Adding "start" and "end" methods to a logger
1 How a function can get its own name
2 Logging function entry and exit

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor