#!/usr/bin/env python3

####################################################################
# BigBrother  CCTV Recording & Live Viewing (mirroring) software   #
# Copyright 2016-2025 Andrew Wood                                  #
#                                                                  #
# bblogger is the BigBrother logging program  used by the various  #
# subprocesses to write to the logfile in a consistent format      #
#								   #
# www.bigbrothercctv.org                                           #
#                                                                  #
# Licensed under the GNU Public License v 3                        #
# The full license can be read at www.gnu.org/licenses/gpl-3.0.txt #
# and is included in the License.txt file included with this       #
# software.                                                        #
#                                                                  #
# BigBrother is free open source software but if you find it       #
# useful please consider making a donation to the Communications   #
# Museum Trust at www.communicationsmuseums.org.uk/donate          #
####################################################################



import sys, os, datetime

if (len(sys.argv) != 2):
	print ("Usage: "+sys.argv[0]+" /path/to/logfile")
	exit(1)

logfilepath=sys.argv[1]


############
def Log(str):
        try:
                now=datetime.datetime.now()
                datestr=now.strftime("%Y-%m-%d %H:%M")
                file=open(logfilepath,'a')
                if str[len(str)-1]!="\n":
                        str=str+"\n"
                file.write(datestr+" "+str)
                file.close()
        except IOError as e:
                        print ("ERROR: Could not open Log file an IOError was thrown")
###########

notEOF=True
while (notEOF):
	try:
		line=line=sys.stdin.read()
		if (line!=""):
			Log(line)
		else:
			notEOF=False
	except KeyboardInterrupt:
		notEOF=False
