Re: Breaking new relic format on a new line character in FileHandler appender

2021-11-11 Thread MRAB

On 2021-11-10 05:16, Vijay Karavadra via Python-list wrote:

Hello Team,

I'm trying to add logs in the new relic platform from a python application.
For that, I've to add logs in a local file in a specific format which is

'{"log.level":"%(levelname)s", "log.entity.name":"my-service-name",
"message":"%(message)s"}'


This works fine in normal scenario and generates the below type of
line in log file and logs are added to new relic with expected
properties set like log level, entity name, message etc.

{"log.level":"INFO", "log.entity.name":"my-service-name", "message":"test"}


This issue occurs when a new line is present in the message property of the
log i.e. on any error we have a message like "Traceback (most recent call
last):" which represents an error traceback after this line with a new line
character. In this case, multiple logs are added instead of a single log,
my expected formatting breaks and logging properties are not set in the new
relic.

Sample breaking log:

{"log.level":"ERROR", "log.entity.name":"my-service-name",
"message":"[Errno 2] No such file or directory:
'E:\\comms-nlp-service\\src\\GoogleAuthentication\\xyz.json' -> Traceback
(most recent call last):
   File "E:\comms-nlp-service\src\app\nlp\carrier_cancel_apiai.py", line 31,
in query
 credentials =
service_account.Credentials.from_service_account_file(filename, scopes
=(scope,))
   File "C:\Python34\lib\site-packages\google\oauth2\service_account.py",
line 209, in from_service_account_file
 filename, require=['client_email', 'token_uri'])
   File
"C:\Python34\lib\site-packages\google\auth\_service_account_info.py", line
71, in from_filename
 with io.open(filename, 'r', encoding='utf-8') as json_file:
FileNotFoundError: [Errno 2] No such file or directory:
'E:\\comms-nlp-service\\src\\GoogleAuthentication\\ xyz  .json'
"}

Any suggestions on this would be a great help.


How about formatting using 'r' or 'a' instead of 's'?

'{"log.level": "%(levelname)s", "log.entity.name": "my-service-name", 
"message": "%(message)r"}'

--
https://mail.python.org/mailman/listinfo/python-list


Re: Avoid nested SIGINT handling

2021-11-11 Thread Paulo da Silva
Às 06:22 de 11/11/21, Chris Angelico escreveu:
> On Thu, Nov 11, 2021 at 5:01 PM Jon Ribbens via Python-list
>  wrote:
>>
>> On 2021-11-10, Paulo da Silva  wrote:
>>> Hi!
>>>
>>> How do I handle a SIGINT (or any other signal) avoid nesting?
>>
>> I don't think you need to. Python will only call signal handlers in
>> the main thread, so a handler can't be executed while another handler
>> is running anyway.
> 
> Threads aren't the point here - signals happen immediately.
> 
> Would it be easier to catch KeyboardInterrupt and do your processing
> there, rather than actually catching SIGINT?
> 
> I'd recommend just trying what you have, and seeing if it's reentrant.
> My suspicion is that it isn't, on a technical level (the Python
> function will be queued for when it's safe to call it - probably after
> the next bytecode instruction), but that your own code will still need
> to worry about reentrancy.
> 
OK, thank you
-- 
https://mail.python.org/mailman/listinfo/python-list