Is there a way in kedro in which I can overwrite t...
# questions
t
Is there a way in kedro in which I can overwrite the info.log file every time it executes. Currently it is appending new run logs.
n
you will need to change the type of logger it is using.
t
can you give me an example if possible;
n
Copy code
info_file_handler:
    class: logging.handlers.RotatingFileHandler
    level: INFO
    formatter: simple
    filename: info.log
    maxBytes: 10485760 # 10MB
    backupCount: 20
    encoding: utf8
    delay: True
This is the default
Do you need to overwrite the file completely? Or you want to keep the record having
info1.log
,
info2.log
etc?
d
or you could use an
after_pipeline_run
hook to just truncate the file
ugly but would work
t
I need to overwrite everytime
I guess it is as simple as changing
mode: w
, I haven’t tested though
t
let me try 🙂
Copy code
info_file_handler:
    class: logging.handlers.RotatingFileHandler
    level: INFO
    formatter: simple
    filename: logs/info.log
    maxBytes: 10485760 # 10MB
    backupCount: 20
    encoding: utf8
    delay: True
    mode: w
i tried this, but still it is appending the logs.
n
No Kedro magic is involved, all pure python
logging
. I just tried and it works. Thanks for asking the question I didn’t know this before too 🙂 The simple solution is don’t use
RotatingFileHandler
, use the basic one.
Copy code
info_file_handler:
    class: logging.FileHandler
    level: INFO
    formatter: simple
    filename: info.log
    delay: True
    encoding: utf8
    mode: w
🚀 2
💪 1