Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About Log Files #1936

Closed
Siraj-Bhai opened this issue May 21, 2024 · 1 comment
Closed

About Log Files #1936

Siraj-Bhai opened this issue May 21, 2024 · 1 comment

Comments

@Siraj-Bhai
Copy link

I work on this for several months. But now I need to check the log files of PGPT. Where can I find the Log Files ? or How to create the Log Files ?

@alxspiker
Copy link
Contributor

Hi @Siraj-Bhai,

To find or create log files for PGPT, you can use the ingest_folder.py script, which includes logging functionality. Here’s how you can do it:

  1. Run the Script with Log File Argument:
    You can specify a log file path using the --log-file argument when running the script. For example:

    python scripts/ingest_folder.py /path/to/folder --log-file /path/to/logfile.log
  2. Log Configuration:
    The script sets up a FileHandler if the --log-file argument is provided. Logs will include timestamps, log levels, and messages.

  3. Example Usage:

    python scripts/ingest_folder.py /data/documents --log-file /logs/pgpt_ingestion.log

This will create a pgpt_ingestion.log file in the specified directory, containing all log messages related to the ingestion process.

Adding Logging to Other Scripts

If you need to add logging to other parts of the project, you can use Python's built-in logging module. Here’s an example of how to set it up:

  1. Import the Logging Module:

    import logging
  2. Configure Logging:

    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        handlers=[
            logging.FileHandler("pgpt.log"),
            logging.StreamHandler()
        ]
    )
  3. Add Logging Statements:

    logger = logging.getLogger(__name__)
    
    def some_function():
        logger.info("This is an info message")
        try:
            # Your code logic here
        except Exception as e:
            logger.error("An error occurred", exc_info=True)

This setup will create a pgpt.log file in the directory where you run your script, containing all log messages.

If you need further assistance or more detailed instructions, feel free to ask!

Best regards,
alxspiker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants