ocfl-java icon indicating copy to clipboard operation
ocfl-java copied to clipboard

Support for logs dir

Open pwinckles opened this issue 4 years ago • 6 comments

How should the logs directory be used? Currently, nothing is written to the logs directory. How do people want to use it?

pwinckles avatar Feb 03 '21 18:02 pwinckles

I could see using logs/ for events like object verification and fixity checks. It'd be nice to have an API for writing some text to a certain file in logs/. There could also be a logger-like API, that would take the text and write it to the file with the current timestamp.

bcail avatar Jun 22 '21 17:06 bcail

@bcail Are you imagining something like:

interface OcflRepository {

    void log(String objectId, String logFileName, String message);

}

Or something like:

interface OcflObjectUpdater {

   void log(String logFileName, String message);

}

Or both? Or something else?

Would you want/need anything more structured than a string message?

pwinckles avatar Jun 22 '21 17:06 pwinckles

I think I'd lean toward the former, since these log messages would be happening separate from object updates. We shouldn't need anything more than a string message.

However, I could see it being useful to be able to specify the log level (INFO, ERROR, ...), and have ocfl-java put that into the log, with the current UTC timestamp. We could add that info to the message ourselves, but if you have a nice way of handling that in ocfl-java, we'd probably use it.

bcail avatar Jun 22 '21 17:06 bcail

Okay, so the current proposal is:

interface OcflRepository {

    void log(String objectId, String logFileName, String message);

    InputStream readLogFile(String objectId, String logFileName);

}

I am slightly hesitant to do something like:

    void logInfo(String objectId, String logFileName, String message);
    void logWarn(String objectId, String logFileName, String message);
    void logError(String objectId, String logFileName, String message);

To produce log lines like:

2021-06-22T18:05:32+00:00 [INFO] message

Because it is much more prescriptive than I care to be. For example, what if someone wants to put JSON objects in their log?

That said, the proposed API also has a problem that it does not support non-line based logging. For example, what if I want my logs to be an XML document with log entries represented as elements within the document (perhaps it's a PREMIS document )? To support something like that it would seem like we'd need an API like:

void writeLogFile(String objectId, String logFileName, InputStream content);

That would overwrite the log file rather than append to it.

Perhaps something like this could make everyone happy?

interface OcflRepository {

    enum Mode {
        APPEND, OVERWRITE
    }

    enum Level {
        DEBUG, INFO, WARN, ERROR
    }

    void log(String objectId, String logFileName, Mode mode, String content);

    void log(String objectId, String logFileName, Level level, String message);

    InputStream readLogFile(String objectId, String logFileName);

}

pwinckles avatar Jun 22 '21 18:06 pwinckles

Note, overwriting the file is a little dangerous as concurrent updates have a race condition.

pwinckles avatar Jun 22 '21 18:06 pwinckles

That final example interface looks OK to me - I think we would just use the log message with the level and the timestamp. I think if we created a PREMIS document, we would put it in the object itself, not the logs directory - but others may want to.

bcail avatar Jun 22 '21 18:06 bcail