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


Groups > comp.lang.python > #95668

Re: Logging to a file from a C-extension

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'subject:file': 0.07; 'list).': 0.09; 'logger': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'python.': 0.11; 'output': 0.13; 'question.': 0.13; 'suggest': 0.15; 'instead.': 0.15; 'code),': 0.16; 'file?': 0.16; 'formatting.': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'master.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Logging': 0.16; 'obviously': 0.16; 'string': 0.17; 'stefan': 0.18; '>>>': 0.20; 'extension': 0.20; 'filtering': 0.22; 'latter': 0.22; 'code.': 0.23; '(where': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'logging': 0.27; 'idea': 0.28; 'directly,': 0.29; 'does,': 0.29; 'allows': 0.30; "i'm": 0.30; "i'd": 0.31; 'implement': 0.32; 'instead,': 0.33; 'file': 0.34; 'except': 0.34; 'could': 0.35; 'level': 0.35; 'reply.': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; '(and': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'received:org': 0.37; 'suggestion': 0.37; 'anything': 0.38; 'log': 0.38; 'skip:p 20': 0.38; 'hi,': 0.38; 'subject:from': 0.39; 'from:': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'care': 0.60; 'your': 0.60; 'received:uk': 0.61; 'details': 0.62; 'received:ac.uk': 0.66; 'here': 0.66; 'reply': 0.68; 'choices:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Logging to a file from a C-extension
Date Wed, 26 Aug 2015 18:39:28 +0200
References <SNT151-W75B708F094CE1F2C687FFFB1780@phx.gbl> <mr2mns$apc$1@ger.gmane.org> <6ED6C17008BE7947AB56195C0C4B7FCF9380D653@SIMTCSMB04.napa.ad.etn.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host global-1-22.nat.csx.cam.ac.uk
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0
In-Reply-To <6ED6C17008BE7947AB56195C0C4B7FCF9380D653@SIMTCSMB04.napa.ad.etn.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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 <http://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>
Newsgroups comp.lang.python
Message-ID <mailman.58.1440607201.11709.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1440607201 news.xs4all.nl 23737 [2001:888:2000:d::a6]:58332
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95668

Show key headers only | View raw


Hi,

welcome to Python (and to this list). The usual way to reply here is
inline, after stripping anything that's not relevant to your reply.


AllanPfalzgraf schrieb am 25.08.2015 um 15:03:
> From: Stefan Behnel:
>> Al Pfalzgraf schrieb am 18.08.2015 um 15:07:
>>> If a logging file is opened at the level of a Python application,
>>> how would the log file name be communicated to a C-extension so that
>>>  logging from the extension would be sent to the same log file?
>> 
>> Writing to the file directly (as was suggested) may not be a good idea
>> as it would bypass the log filtering and formatting. Instead, I'd
>> suggest sending output to a normal Python Logger object instead.
>> 
>> This is obviously trivial in Cython (where you can just implement it
>> in Python code), but you can do the same in C with just the usual
>> C-API overhead.
> 
> You have understood my question.  I'm new to Python.  Could I use a
> Cython solution to get suggestions on just how to go about this in the C
> extension?  Otherwise could you suggest which C-API functions I should
> be looking at?

Well, my suggestion would be to write the extension in Cython instead of C,
simply because it allows you to care about what you want to achieve instead
of having to concentrate on C-API details like this which try to get in
your way and are difficult to master.

However, if you really want to use the CPython C-API directly, you have two
choices: write the logging setup in Python and execute it from a C string
using PyRun_SimpleString(), or reimplement what Python would do in C using
PyImport_AddModule, PyObject_GetAttr and PyObject_Call*(). The latter is
also what Cython does, except that it generates faster code.

Stefan

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Logging to a file from a C-extension Stefan Behnel <stefan_ml@behnel.de> - 2015-08-26 18:39 +0200

csiph-web