Project

General

Profile

Revision 426

logging stuff no longer occurs by default in server

View differences:

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) {

Also available in: Unified diff