Answers for "write log file batch script"

3

linux show log file real time

$ sudo tail -f /var/log/apache2/access.log
Posted by: Guest on August-28-2020
6

python logging to file

import logging

"""
DEBUG
INFO
WARNING
ERROR
CRITICAL
"""
# asctime: time of the log was printed out
# levelname: name of the log
# datefmt: format the time of the log
# give DEBUG log
logging.basicConfig(format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
    datefmt='%d-%m-%Y:%H:%M:%S',
    level=logging.DEBUG,
    filename='logs.txt')

logger = logging.getLogger('my_app')

logger.debug("This is a debug log")
logger.info("This is an info log")
logger.critical("This is critical")
logger.error("An error occurred")
Posted by: Guest on August-13-2020
0

output to log file and error to log error

./ShellFile.sh >& pathToLogFile.log
Posted by: Guest on November-19-2020

Python Answers by Framework

Browse Popular Code Answers by Language