FS2_Open
Open source remastering of the Freespace 2 engine
multi_log.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 
13 #include <stdarg.h>
14 #include "network/multi_log.h"
15 #include "parse/generic_log.h"
16 #include "cfile/cfile.h"
17 #include "parse/parselo.h"
18 
19 
20 
21 // ----------------------------------------------------------------------------------------------------
22 // MULTI LOGFILE DEFINES/VARS
23 //
24 
25 // max length for a line of the logfile
26 #define MAX_LOGFILE_LINE_LEN 256
27 
28 // how often we'll write an update to the logfile (in seconds)
29 #define MULTI_LOGFILE_UPDATE_TIME 2520 // every 42 minutes
30 
31 // time when the logfile was opened
33 
34 // time when we last updated the logfile
36 
37 // ----------------------------------------------------------------------------------------------------
38 // MULTI LOGFILE FUNCTIONS
39 //
40 
41 // write the standard header to the logfile
43 {
44  char str[1024];
45  time_t timer;
46 
47  // header message
48  timer = time(NULL);
49  strftime(str, 1024, "FreeSpace Multi Log - Opened %a, %b %d, %Y at %I:%M%p\n----\n----\n----\n\n", localtime(&timer));
50  log_string(LOGFILE_MULTI_LOG, str, 0);
51 }
52 
53 // write the standard shutdown trailer
55 {
56  char str[1024];
57  time_t timer;
58 
59  // header message
60  timer = time(NULL);
61  strftime(str, 1024, "\n\n----\n----\n----\nFreeSpace Multi Log - Closing on %a, %b %d, %Y at %I:%M%p", localtime(&timer));
62  log_string(LOGFILE_MULTI_LOG, str, 0);
63 }
64 
65 // write out some info about stuff
67 {
68  int diff = (int)difftime(time(NULL), Multi_log_open_systime);
69  int hours, mins, seconds;
70 
71  // figure out some time values
72  hours = diff / 3600;
73  mins = (diff - (hours * 3600)) / 60;
74  seconds = (diff - (hours * 3600) - (mins * 60));
75 
76  // print it out
77  ml_printf("Server has been active for %d hours, %d minutes, and %d seconds", hours, mins, seconds);
78 }
79 
80 // initialize the multi logfile
82 {
85 
86  // initialize our timer info
87  Multi_log_open_systime = (int) time(NULL);
89  }
90 }
91 
92 // close down the multi logfile
94 {
97 }
98 
99 // give some processing time to the logfile system so it can check up on stuff
101 {
102  // check to see if we've been active a long enough time, and
104  // write the update
106 
107  Multi_log_update_systime = (int) time(NULL);
108  }
109 }
110 
111 // printf function itself called by the ml_printf macro
112 void ml_printf(const char *format, ...)
113 {
115  va_list args;
116 
117  if (format == NULL) {
118  return;
119  }
120 
121  // format the text
122  va_start(args, format);
123  vsprintf(temp, format, args);
124  va_end(args);
125 
126  // log the string including the time
127  log_string(LOGFILE_MULTI_LOG, temp.c_str(), 1);
128 }
129 
130 // string print function
131 void ml_string(const char *string, int add_time)
132 {
133  char tmp[MAX_LOGFILE_LINE_LEN*4];
134  char time_str[128];
135  time_t timer;
136 
137  // if the passed string is NULL, do nothing
138  if(string == NULL){
139  return;
140  }
141 
142  // maybe add the time
143  if(add_time){
144  timer = time(NULL);
145 
146  strftime(time_str, 128, "%m/%d %H:%M:%S~ ", localtime(&timer));
147  strcpy_s(tmp, time_str);
148  strcat_s(tmp, string);
149  } else{
150  strcpy_s(tmp, string);
151  }
152  strcat_s(tmp, "\n");
153 
154  // now print it to the logfile if necessary
155  log_string(LOGFILE_MULTI_LOG, tmp, 0);
156 
157  // add to standalone UI too
158  extern int Is_standalone;
159  extern void std_debug_multilog_add_line(const char *str);
160  if (Is_standalone) {
162  }
163 
164 #if defined(MULTI_LOGFILE_ECHO_TO_DEBUG)
165  // nprintf(("Network","%s\n",tmp));
166  mprintf(("ML %s", tmp));
167 #endif
168 }
GLenum GLsizei GLenum format
Definition: Gl.h:1509
void std_debug_multilog_add_line(const char *str)
#define mprintf(args)
Definition: pstypes.h:238
void multi_log_close()
Definition: multi_log.cpp:93
void multi_log_process()
Definition: multi_log.cpp:100
void ml_string(const char *string, int add_time)
Definition: multi_log.cpp:131
#define MAX_LOGFILE_LINE_LEN
Definition: multi_log.cpp:26
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
void log_string(int logfile_type, const char *string, int add_time)
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
void ml_printf(const char *format,...)
Definition: multi_log.cpp:112
void vsprintf(SCP_string &dest, const char *format, va_list ap)
Definition: parselo.cpp:3800
void multi_log_init()
Definition: multi_log.cpp:81
void multi_log_write_trailer()
Definition: multi_log.cpp:54
void logfile_close(int logfile_type)
Definition: generic_log.cpp:72
#define MULTI_LOGFILE_UPDATE_TIME
Definition: multi_log.cpp:29
int Multi_log_update_systime
Definition: multi_log.cpp:35
int Multi_log_open_systime
Definition: multi_log.cpp:32
#define LOGFILE_MULTI_LOG
Definition: generic_log.h:18
#define strcat_s(...)
Definition: safe_strings.h:68
bool logfile_init(int logfile_type)
Definition: generic_log.cpp:53
int temp
Definition: lua.cpp:4996
void multi_log_write_header()
Definition: multi_log.cpp:42
void multi_log_write_update()
Definition: multi_log.cpp:66
#define strcpy_s(...)
Definition: safe_strings.h:67
int Is_standalone
Definition: systemvars.cpp:59