/*
    ORPP Client

    (C) 2005 Jason Hunt

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    Contact: huntjas2@msu.edu

    Compile with -lwsock32

    FILE: log.cpp
    
    Logging with time stamp
*/

#include <windows.h>
#include <stdio.h>

#pragma hdrstop

#include "key.h"
#include "display.h"

bool logging_enabled = false;

/* accessor functons for logging state */
void set_logging(bool new_state)
{
    logging_enabled = new_state;
}
/* end of set_logging */


/* accessor functons for logging state */
bool get_logging( void )
{
    return(logging_enabled);
}
/* end of set_logging */


/* adds an item to the log file */
void addlog(char *s)
{
    SYSTEMTIME st;
    GetLocalTime(&st); 

    FILE *f = fopen("log.txt", "at");   

    if (!f)
    {
        add_line("Unable to create log file");
        return;
    }
    
    fprintf(f, "[%d/%d/%d - %d:%d:%d%] %s\n",st.wMonth, st.wDay, st.wYear, 
                                             st.wHour, st.wMinute, st.wSecond, s);

    fclose(f);  // this is slow, but we want whatever data we have if the client crashes
}
/* end of log */
















