# enamine_query_logger.py - script functions for logging Enamine Web Services activity
# Use of this code is subject to the terms of the StarDrop License Agreement and use, copying or redistribution of
# this file for use by other persons or organisations is prohibited
# Copyright(C) Optibrium Ltd 2026
# support@optibrium.com
#
"""
Module to manage logging of Enamine Web Services activity
"""

import os
import datetime


class EnamineQueryLogger:
    """EnamineQueryLogger represents a single log file that can be writen to."""

    def __init__(self, filename):
        """Construct a QueryLogger with a file.
        @param: filename: The full path to the file to be used for logging.
        """
        self.filename = filename
        if not os.path.isfile(self.filename):
            fout = open(self.filename, 'w')
            fout.close()

    def log(self, message):
        """Write a message to the log file.
        @param: message: The text to log
        """
        fout = open(self.filename, 'a')
        dt = datetime.datetime.now()
        fout.write(dt.strftime('%d/%m/%Y %H:%M ') + message + '\n')
        fout.close()
