1

I have a powershell script and I save the log using this way

$Log = Start-Transcript -Path $Log_Path -Force

How do I use it in Python?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Job
  • 415
  • 1
  • 11
  • 31
  • Is your file available on the system after having called your powershell ? – cocool97 Aug 05 '19 at 10:12
  • Possible duplicate of [Making Python loggers output all messages to stdout in addition to log file](https://stackoverflow.com/questions/14058453/making-python-loggers-output-all-messages-to-stdout-in-addition-to-log-file) – R4444 Aug 06 '19 at 05:23

2 Answers2

4

You can write/save the log file using the below command.

logging.basicConfig(filename='path to the log file', level=...)

There is a filemode option to overwrite the file. To overwrite you can specifie filemode:w

logging.basicConfig(filename='logs.log',
            filemode='w',
            level=logging.INFO)

filemode: Specifies the mode to open the file, if filename is specified (if filemode is unspecified, it defaults to ‘a’).

Yashi Aggarwal
  • 407
  • 2
  • 6
1

There is a logging module in python. You can import an use that.

import logging logging.basicConfig(level=logging.DEBUG) logging.debug('This will get logged')

And the output will be:

DEBUG:root:This will get logged

Similarly, you can use the other log levels too. You can find more about it here

Nitin Sharma
  • 57
  • 11