Breaking new relic format on a new line character in FileHandler appender
Vijay Karavadra
vijay.karavadra at marutitech.com
Wed Nov 10 00:16:03 EST 2021
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.
--
Thanks,
Vijay Karavadra
More information about the Python-list
mailing list