Tutorial: Folder Organisation for Logs

So thought Id get something written down to document my idea for a more complex log system which would more likely prove more helpful for more complex interrogations etc.

Anyway my plan is to keep a log of all updates made in Samba based on information drawn from the REST API of the PMS system I am creating an integration for.

While obviously I plan not to have any issues there is always the potential for problems moving from a test environment to a production environment.

As I am integrating 40 rooms with 8-10 fields a single line text file log would be unsuitable.

The script I have to update the rooms data will run every 10-15 minutes so plan to have a script run log which will be a single txt file per day with log of if the script ran and what rooms were updated.
I then plan to create a text file for the data which gets updated.

The planned structure would be;

C:\SambaPOS\Logs\LOG FOLDER \ YEAR \ MONTH \ DAY \

Log folder will be left as a top level directory for any future log implementations.
This one will be ‘Room Updates’
C:\ SambaPOS \ Logs \ Room Updates

My scripts will be tiered ie

`Update Script -- (Log Output: Date & Log) --> Log Script --> Log Folder Script (Using Date)`
                                                          --> Log Script Add Line (Using Date & Log)

Starting from the end backwards I have made a script to check if the date based directory exists in the log directory folder.

I have configured with the help of @QMcKay a way to define a single script page of variables to be used in all other scrips where needed allowing a single place to update variables for multiple scripts.
In this I have defined a log ‘root’ directory;

var logFolderDirectory = ‘C:/SambaPOS/Logs’

In order to create and check folder existence I had to load ActiveXObject("Scripting.FileSystemObject")

This script will take the input date and folder and create a directory for the log date;
\SambaPOS\Logs\test\2015\12\26
when script LogFolder.directoryCheck(‘26/12/2015’,‘test’) is run.

Hope someone finds this useful :smile:

Here is a ‘Generalized’ directory tool/script;

var fso = new ActiveXObject("Scripting.FileSystemObject");																	//Load folder creation tools

function directoryCheck(inputdate,inputfolder) {
	
	//Variable definitions
	var dirDirectory	= 'C:/SambaPOS/Logs/';																				//Root directory (MUST EXIST)
	var dirdate 		= inputdate;																						//Directory date for folders
	var dirfolder 		= inputfolder;																						//Top level directory folder
	
	//Seperate Day, Month & Year from log date
	var dirdateYear		= dirdate.getYear();																				//Seperate Year from Log Date
	var dirdateMonth	= dirdate.getMonth()+1;																				//Seperate Month from Log Date
	var dirdateDay		= dirdate.getDate();																				//Seperate Day from Log Date

	//Check Update Script Log folder exists if not create it		
	if (fso.FolderExists(dirDirectory+'/'+dirfolder))																		//Does specified log folder exisit?
	 	{
																															//Do nothing if exists	 	
	 	} else {
			fso.CreateFolder(dirDirectory+'/'+dirfolder);																	//Create folder if not
		}

	//Check log year folder exists if not create it
	if (fso.FolderExists(dirDirectory+'/'+dirfolder+'/'+dirdateYear))														//Does specified log year folder exisit?
	 	{
																														 	//Do nothing if exists	 	
	 	} else {
			fso.CreateFolder(dirDirectory+'/'+dirfolder+'/'+dirdateYear);													//Create folder if not
		}
	
	//Check log month folder exists if not create it
	if (fso.FolderExists(dirDirectory+'/'+dirfolder+'/'+dirdateYear+'/'+dirdateMonth))										//Does specified log year folder exisit?
	 	{
																															//Do nothing if exists	 	
	 	} else {
			fso.CreateFolder(dirDirectory+'/'+dirfolder+'/'+dirdateYear+'/'+dirdateMonth);									//Create folder if not
		}
	
	//Check log day folder exists if not create it
	if (fso.FolderExists(dirDirectory+'/'+dirfolder+'/'+dirdateYear+'/'+dirdateMonth+'/'+dirdateDay))						//Does specified log day folder exisit?
	 	{
																															//Do nothing if exists	 	
	 	} else {
			fso.CreateFolder(dirDirectory+'/'+dirfolder+'/'+dirdateYear+'/'+dirdateMonth+'/'+dirdateDay);					//Create folder if not
		}
		
}

This would be called with HANDLER.directoryCheck(‘DATE’,‘FOLDER’) where bold would been dependent on your system/setup.

var dirDirectory	= 'C:/SambaPOS/Logs/';																	
var dirdate 		= inputdate;																						
var dirfolder 		= inputfolder;		

These can be used to bypass the input from the script call ()
dirDirectory should be set manually and MUST exist.

1 Like