简体   繁体   中英

Unable to create log files in EC2 instance using python

I am running a script in EC2 instance as job (through task scheduler) which creates its own log file. On my local machine it runs perfectly fine and creates the file, but on EC2 i'm not able to see the file at all.

Here is the sample code

import logging
import logging.handlers

def setup_logging(logger, logfile):
    logger.setLevel(logging.INFO)
    handler = logging.handlers.RotatingFileHandler(
        logfile, maxBytes=(1048576 * 5), backupCount=7)
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    console_handler = logging.StreamHandler()
    console_handler.setFormatter(formatter)
    logger.addHandler(console_handler)


logfile = 'one_time_loader'
logger = logging.getLogger()
setup_logging(logger, logfile)

for i in range(0,1000):
    logger.info(i)

Kindly help me to resolve it.

You'll need to import Boto3 from the AWS SDK. https://aws.amazon.com/sdk-for-python/ Since you're running it as an EC2 instance type, you'll need to make calls against the Resource APIs. See the doc for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM