Copy link to clipboard
Copied
I've got a script on a server that 40+ people access and use through an action in Photoshop. It does a number of checks/corrections to the users open images before closing and uploading them to our website. It also has built in logging through a function that writes to several '.log' files on the server based on what corrections have been made to the current image. There's also a general log that logs what images were processed, by which user and at which time, all written to the same 'Uploaded.log' file.
This is a snippet of the log function, which demonstrates its essence:
// If log file already exists
if (logFile.exists) {
// Read log
logFile.open("r");
var logDataString = logFile.read();
logFile.close();
// Write saved and new data to file
logFile.open("w");
logFile.write(logDataString);
logFile.writeln(timeAndDate + " - " + logData + " - " + USER_NAME);
logFile.close();
// If file doesn't exist, create and write new data
} else {
logFile.open("w");
logFile.writeln(timeAndDate + " - " + logData + " - " + USER_NAME);
logFile.close();
}
What the function essentially does is read the log file by pulling it into a variable, appends whatever activity the user has done, and then re-writes the log file to the server, overwriting the old one. However, what happens fairly often due to the amount of users writing to it at the same time is one user might be in the middle of overwriting the file while another is reading, so a big chunk of it can get lost in this overlap.
Could any of you recommend a way to avoid this? I was thinking of having the function create a temp file before it starts logging and then deletes when it's finished. That way, I could have it check for this file and only start logging once it's been deleted by another running the script. So, a simple while loop like this:
while(tempFile.exists){
// do nothing
}
Would this be an effective solution?
Copy link to clipboard
Copied
Could you log data directly inside images metatags? This is technicaly possible.
Photoshop can do it with PSD by default. Just turn feature on in settings. The only thing you need is to add is username.
Copy link to clipboard
Copied
I'd prefer to have all the logging done to 1 -3 files in one location rather than within all the images themselves.
Copy link to clipboard
Copied
I wonder if it would be put to use Google Analytics. It is possible to send your own events. You could also filter by event type quite easy.
I think in your own panel, this is not a problem, because it renders webkit. But it must be shown, otherwise html is not loaded. Maybe it could be done without it.
Copy link to clipboard
Copied
During working hours have each user write to a unique user-specific log file. Then after working hours set up an automatic process that concatenates all of the logs into one and then sorts each line by it's timeAndDate.
I'm sure there's a wide variety of ways to go about the automation part, but it seems to me a bash shell script with a cron job (set to run the script at 2:00am, for example) would do the trick. The line sorting can be accomplished with just regex, but for an easier solution check out an awesome program called textsoap.
Copy link to clipboard
Copied
Apologies for the delay in my response! I'm afraid I don't have access and wouldn't get permission to run something like that.