#
# gpcupslogger.rb
# Encapsulates logging to an external file.
#
# Copyright (c) 2003-2014 GoPrint Systems, Inc.  All rights reserved.
#

module GoPrintCUPSLogger
	# Initialize the logger
	def initialize(config)
		@loggingEnabled = config.loggingEnabled
		if (@loggingEnabled)
			@debugFile = File.open(config.logFileName, "a+")
		end
	end

	# Log the given message if logging is enabled
	def log(logMsg)
		if (@loggingEnabled)
			@debugFile.puts Time.now.to_s + " " + logMsg
		end
	end

	def flushLog()
		if (@loggingEnabled)
			@debugFile.flush
		end
	end

	# Close the log
	def closeLog()
		if (@loggingEnabled)
			@debugFile.flush
			@debugFile.close
		end
	end
end
