Skip to content

idslayer/Programming-Principles-Assessment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Programming-Principles-Assessment

🧠 Distributed Log File Analysis System

Student Name: Truong Minh Phuong
Student ID: 29697148 Module: Programming Principles(CMP9133)

A C++ client-server application for parsing and analyzing log files in JSON, TXT, and XML formats using multithreading and TCP networking.

✅ Final coursework project for Programming Principles – MSc Computer Science Applied, University of Lincoln.


🚀 Features

  • 🔌 TCP client-server architecture
  • 🧵 Multithreaded server (each client handled in a detached thread)
  • 📂 Support for JSON, TXT, and XML log formats
  • 🧠 Analysis by:
    • USER – Count logs by user_id
    • IP – Count logs by ip_address
    • LOG_LEVEL – Count logs by level (INFO, WARN, ERROR, etc.)
  • 📅 Optional FROM and TO date range filtering
  • 📤 Client can batch-send multiple logs from a folder
  • 🧱 Raw parsing (no XML/JSON parser dependencies except nlohmann JSON)

📁 Project Structure

/
├── client/
│   └── client.cpp            # Console-based log sender
├── server/
│   ├── server.cpp            # Multithreaded TCP server
│   ├── parser/
│   │   ├── log_parser.hpp    # Abstract parser interface
│   │   ├── json_parser.hpp   # JSON parser (uses nlohmann)
│   │   ├── txt_parser.hpp    # TXT parser (manual)
│   │   ├── xml_parser.hpp    # XML parser (manual tag-matching)
│   │   └── lib/nlohmann/     # nlohmann/json.hpp
├── logs/                     # Sample log files for testing
├── README.md                
└── Makefile                  # Optional build script

🔧 How It Works

✅ Client

  • Prompts for:
    • Server IP and port
    • Analysis type (USER, IP, LOG_LEVEL)
    • Optional FROM and TO dates (YYYY-MM-DD)
    • Log folder path
  • Sends each file in the folder to the server
  • Receives and prints the analysis result per file

✅ Server

  • Listens for client connections on TCP port 8080
  • For each connection (threaded):
    • Parses the header: TYPE, FROM, TO
    • Detects log format: .json, .txt, or .xml
    • Applies date filtering
    • Analyzes content using the appropriate parser
    • Returns result to client

📜 Log File Formats

🧾 JSON

[
  {
    "timestamp": "2024-09-30 22:51:48",
    "log_level": "INFO",
    "message": "Service started",
    "user_id": 1234,
    "ip_address": "10.0.0.1"
  }
]

🧾 TXT

2024-09-30 22:51:48 | INFO | Service started | UserID: 1234 | IP: 10.0.0.1

🧾 XML

<logs>
  <log>
    <timestamp>2024-09-30 22:51:48</timestamp>
    <log_level>INFO</log_level>
    <message>Service started</message>
    <user_id>1234</user_id>
    <ip_address>10.0.0.1</ip_address>
  </log>
</logs>

⚙️ Build Instructions

🛠 Requirements

  • C++17 compiler
  • POSIX-compatible OS (Linux/macOS)
  • make (optional)

🧱 Build

# Server
g++ -pthread -o server_app  server/server.cpp  

# Client
g++  client/client.cpp -o client_app  

Or use:

make

▶️ Run

# Terminal 1
./server

# Terminal 2
./client

💡 Example Use Case

  1. Start server
  2. Start client, input:
  • IP: 127.0.0.1
  • Port: 8080
  • Type: LOG_LEVEL
  • FROM: 2024-09-01
  • TO: 2024-09-30
  • Folder: ./logs/client#1
  1. Result:
  • Summary of log counts by user for files within that folder

📷 Response

=== Analysis Result for log_file.xml ===
INFO: 183013
ERROR: 183696
DEBUG: 183354
WARN: 183742
CRITICAL: 182880
=== End of log_file.xml ===

=== Analysis Result for log_file.txt ===
INFO: 183177
CRITICAL: 183468
WARN: 183314
ERROR: 183563
DEBUG: 183477
=== End of log_file.txt ===

=== Analysis Result for log_file.json ===
ERROR: 183519
DEBUG: 183202
INFO: 184210
WARN: 183117
CRITICAL: 183277
=== End of log_file.json ===


📦 Third-Party Library

Used for JSON parsing in json_parser.hpp. This is a header-only modern C++ JSON library under the MIT License.

The MIT License (MIT)

Copyright (c) 2013-2024 Niels Lohmann
Permission is hereby granted, free of charge...

See full license in parser/lib/nlohmann/LICENSE.MIT.


🔍 Educational Value

This project demonstrates:

  • ✅ Network programming with low-level sockets
  • ✅ File parsing and validation across formats
  • ✅ Use of abstraction and inheritance (LogParser)
  • ✅ Threading with std::thread
  • ✅ Input validation and error handling

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages