Debian Codegraph @

terps/jacl/logging.c

raw symbols SCIP
1 /* logging.c --- Logging functions
2 * (C) 2008 Stuart Allen, distribute and use
3 * according to GNU GPL, see file COPYING for details.
4 */
5
6 #include "jacl.h"
7 #include "types.h"
8 #include "prototypes.h"
9 #include "language.h"
10
11 #ifdef __NDS__
12 void
13 log_error(const char *message, int console)
14 {
15 char consoleMessage[256];
16
17 sprintf(consoleMessage, "ERROR: %s^", message);
18
19 write_text(consoleMessage);
20 }
21 #endif
22 #ifdef GLK
23 void
24 log_error(const char *message, int console)
25 {
26 /* LOG A MESSAGE TO THE CONSOLE */
27
28 char consoleMessage[256];
29 event_t event;
30
31 // BUILD A STRING SUITABLE FOR DISPLAY ON THE CONSOLE.
32 sprintf(consoleMessage, "ERROR: %s^", message);
33
34 glk_set_style(style_Alert);
35 write_text(consoleMessage);
36 glk_set_style(style_Normal);
37
38 // FLUSH THE GLK WINDOW SO THE ERROR GETS DISPLAYED IMMEDIATELY.
39 glk_select_poll(&event);
40 }
41 #endif
42 #ifndef GLK
43 #ifndef __NDS__
44 extern char error_log[];
45 extern char access_log[];
46
47 void
48 log_access(const char *message)
49 {
50 /* LOG A MESSAGE TO THE ACCESS LOG */
51
52 FILE *accessLog = fopen(access_log, "a");
53
54 if (accessLog != NULL) {
55 fputs(message, accessLog);
56 fflush(accessLog);
57 fclose(accessLog);
58 }
59 }
60
61 void
62 log_error(const char *message, int console)
63 {
64 FILE *errorLog = fopen(error_log, "a");
65 time_t tnow;
66 char consoleMessage[256];
67 char temp_buffer[256];
68
69 time(&tnow);
70 /* MAKE THE LOG MESSAGE WITH TIME, USER_ID AND GAME PREFIX */
71 sprintf(temp_buffer, "%s - %s - %s - %s\n", strip_return(ctime(&tnow)), user_id, prefix, message);
72
73 /* MAKE THE MESSAGE FOR STDERR AND STDOUT WITH ERROR PREFIX */
74 sprintf(consoleMessage, "%s: %s", prefix, message);
75
76 if (console < ONLY_STDERR) {
77 if (errorLog != NULL) {
78 fputs(temp_buffer, errorLog);
79 fflush(errorLog);
80 fclose(errorLog);
81 }
82 }
83
84 /* SEND THE MESSAGE TO STANDARD ERROR OR STANDARD OUT AS REQUIRED */
85 if (console == PLUS_STDOUT || console == ONLY_STDOUT) {
86 write_text(consoleMessage);
87 write_text("^");
88 } else if (console == PLUS_STDERR || console == ONLY_STDERR) {
89 fprintf(stderr, "%s", consoleMessage);
90 fprintf(stderr, "%s", "\n");
91 fflush(stderr);
92 }
93 }
94
95 void
96 log_debug(const char *message, int console)
97 {
98 log_message(message, console);
99 }
100
101 void
102 log_message(const char *message, int console)
103 {
104 FILE *errorLog = fopen(error_log, "a");
105 time_t tnow;
106 char consoleMessage[256];
107 char temp_buffer[256];
108
109 /* MAKE THE LOG MESSAGE WITH GAME PREFIX */
110 sprintf(temp_buffer, "%s - %s - %s\n", strip_return(ctime(&tnow)), prefix, message);
111
112 /* MAKE THE MESSAGE FOR STDERR AND STDOUT WITH ERROR PREFIX */
113 sprintf(consoleMessage, "%s: %s\n", prefix, message);
114
115 if (errorLog != NULL) {
116 fputs(temp_buffer, errorLog);
117 fflush(errorLog);
118 fclose(errorLog);
119 }
120
121 /* SEND THE MESSAGE TO STANDARD ERROR OR STANDARD OUT AS REQUIRED */
122 if (console == 1) {
123 write_text(message);
124 write_text("^");
125 } else if (console == 2) {
126 fprintf(stderr, "%s\n", message);
127 fflush(stderr);
128 }
129 }
130 #endif
131 #endif