Apify

Apify and Crawlee Official Forum

b
F
A
J
A

Custom LoggerText implementation not handling objects

hey folks,
I had to write up a custom logger implementation because I needed to store the logs in a file and rotate them as well. I have extended LoggerText and have implemented the methods as well and while its working its skipping a lot of debug messages that we get with the inbuilt logger as well as not being able to handle objects being passed to it. I have looked at the source code for it and have stuck to it as much as I could.

I would really appreciate it if someone could point out whats wrong with it.

code: https://pastebin.com/tpGxyM0P

actual output: https://pastebin.com/ABtC8QSa
A
L
10 comments
on further debugging, it looks like in the log method, all of the data being sent is treated as exception
ok I fixed the debug stuff by flipping the order of function variables and making it like its there in the _log func
but the json is adding \ everywhere which I know is to skip double quotes but its not like that in the crawlee implementation, is there something I can do to fix it?
also I am calling _parseException just like in _log but its not parsing the exception at all and instead has undefined
and I am passing an exception along like this
Plain Text
try{
../code
}catch(error:any){
//any fixes for this any? it looks really ugly but ts wont let me pass it in without any
log.error('error',error)
}
Leaving this for others but this is how I fixed it https://pastebin.com/3awiV7ce
only issue I can find with crawlee's implementation is, I had to break out winston's logger in a separate function because crawlee's log would keep overriding my routes.ts settings if I imported a different file which was using a crawlee log too, Not sure if its supposed to be a bug or anything
as for double encoding, that was winston's json formatter shenanigans, we are already encoding our json into strings inside _log and winston was further encoding it as per my setup
Thanks, I will pass it to the team to make example
Add a reply
Sign up and join the conversation on Discord
Join