Project

General

Profile

Revision 426

logging stuff no longer occurs by default in server

View differences:

trunk/code/projects/colonet/ColonetServer/Log.cpp
40 40
 * @brief Destructor for the Log class
41 41
 */
42 42
Log::~Log() {
43
  if (!log_file)
43
  if (!log_file) {
44 44
    fclose(log_file);
45
  }
45 46
}
46 47

  
47 48
/**
trunk/code/projects/colonet/ColonetServer/includes/ColonetServer.h
6 6
#ifndef COLONETSERVER_H
7 7
#define COLONETSERVER_H
8 8

  
9
#include "ConnectionPool.h"
10
#include "Log.h"
9
#include <ConnectionPool.h>
10
#include <Log.h>
11 11

  
12 12
class ColonetServer {
13 13
public:
......
21 21

  
22 22
private:
23 23
  ConnectionPool connection_pool;
24
  Log logger;
24
  Log* logger;
25 25
  int listen_socket;
26 26

  
27 27
  int initialize_wireless(void);
trunk/code/projects/colonet/ColonetServer/includes/options.h
21 21

  
22 22
extern ColonetServerOptionsT optionsG;
23 23

  
24
void parseCmdLine(int argc, char** argv);
24
void options_parseCmdLine(int argc, char** argv);
25 25

  
26 26
#endif
trunk/code/projects/colonet/ColonetServer/includes/Log.h
23 23
class Log {
24 24
public:
25 25
  Log(char * fileName);
26
  ~Log();
26
  ~Log(void);
27 27

  
28 28
  int log_string(int type, char * message);
29 29
  int log_error(char * message);
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp
35 35
/**
36 36
 * @brief Default constructor for ColonetServer
37 37
 */
38
ColonetServer::ColonetServer(): logger("logFile.txt") {
38
ColonetServer::ColonetServer() {
39 39
  listen_socket = 0;
40 40
}
41 41

  
......
54 54
 * @return 0 on success, negative error code on failure
55 55
 */
56 56
int ColonetServer::initialize_server(int argc, char * argv[]) {
57
  parseCmdLine(argc, argv);
57
  options_parseCmdLine(argc, argv);
58 58

  
59
  if (optionsG.logging_enabled) {
60
    logger = new Log("colonet_server_log.txt");
61
  }
62

  
59 63
  if (initialize_connection(optionsG.listen_port) < 0) {
60 64
    return -1;
61 65
  }
......
75 79
 */
76 80
int ColonetServer::start_listening() {
77 81
  if (listen(listen_socket, LISTEN_BACKLOG) < 0) {
78
    logger.log_error("\t\nThere was an error telling the socket to "
79
		     "listen for connections from clients.  Terminating Server...\n");
82
    if (optionsG.logging_enabled) {
83
      logger->log_error("\t\nThere was an error telling the socket to listen for connections from clients.  "
84
                        "Terminating Server...\n");
85
    }
80 86
    return -1;
81 87
  }
82 88
  return 0;
83 89
}
84 90

  
85

  
86 91
/**
87 92
 * @brief Starts the server running (starts an infinite loop)
88 93
 */
......
93 98
  struct sockaddr_in client_addr;
94 99
  socklen_t client_addr_size = sizeof(client_addr);
95 100

  
96
  logger.log_message("Server initialized.  About to start listening for connections");
101
  if (optionsG.logging_enabled) {
102
    logger->log_message("Server initialized.  About to start listening for connections");
103
  }
97 104

  
98 105
  while(1) {
99 106
    usleep(10000);
......
118 125
        continue;
119 126
      }
120 127

  
121
      char log_buffer[LOG_BUFFER_LENGTH];
122
      snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.",
123
        inet_ntoa(client_addr.sin_addr));
124
      logger.log_string(LOG_TYPE_CONNECT, log_buffer);
128
      if (optionsG.logging_enabled) {
129
	char log_buffer[LOG_BUFFER_LENGTH];
130
	snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.",
131
                 inet_ntoa(client_addr.sin_addr));
132
	logger->log_string(LOG_TYPE_CONNECT, log_buffer);
133
      }
125 134

  
126 135
      if (connection_pool.add_client(accept_socket) < 0) {
127 136
        printf("\tThere was an error when trying to add a client to the connection pool.");
128 137
        continue;
129 138
      }
130 139

  
131
      snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.",
132
        inet_ntoa(client_addr.sin_addr));
133
      logger.log_string(LOG_TYPE_CONNECT, log_buffer);
140
      if (optionsG.logging_enabled) {
141
	char log_buffer[LOG_BUFFER_LENGTH];
142
        snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.",
143
                 inet_ntoa(client_addr.sin_addr));
144
        logger->log_string(LOG_TYPE_CONNECT, log_buffer);
145
      }
134 146
    }
135 147

  
136 148
    if (connection_pool.check_clients() < 0) {
trunk/code/projects/colonet/ColonetServer/options.c
39 39
 *
40 40
 * @return Void
41 41
 */
42
void parseCmdLine(int argc, char** argv) {
42
void options_parseCmdLine(int argc, char** argv) {
43 43
  int c;
44 44

  
45 45
  memset(&optionsG, 0, sizeof(ColonetServerOptionsT));

Also available in: Unified diff