DinoPLayZ commited on
Commit
62b4c70
Β·
verified Β·
1 Parent(s): 29e7786

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +39 -87
main.py CHANGED
@@ -752,6 +752,17 @@ async def root(request: Request):
752
  health_data = await health_check()
753
  assistant_data = await internal_assistant()
754
 
 
 
 
 
 
 
 
 
 
 
 
755
  # Format nicely as JSON strings
756
  health_json = json.dumps(health_data, indent=2)
757
  assistant_json = json.dumps(assistant_data, indent=2)
@@ -877,6 +888,23 @@ async def root(request: Request):
877
  .null {{ color: #ff7b72; }}
878
  .key {{ color: #7ee787; font-weight: 600; }}
879
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
880
  @keyframes fadeIn {{
881
  from {{ opacity: 0; transform: translateY(5px); }}
882
  to {{ opacity: 1; transform: translateY(0); }}
@@ -900,7 +928,7 @@ async def root(request: Request):
900
  <div class="tabs">
901
  <button class="tab-btn active" onclick="switchTab('health')">πŸ₯ Health</button>
902
  <button class="tab-btn" onclick="switchTab('assistant')">πŸ€– Assistant</button>
903
- <a href="/logs" target="_blank" class="tab-btn" style="text-decoration: none; display: inline-block;">πŸ“œ View Logs</a>
904
  </div>
905
 
906
  <div id="health" class="tab-content active">
@@ -910,6 +938,10 @@ async def root(request: Request):
910
  <div id="assistant" class="tab-content">
911
  <pre class="code-block" id="assistant-json">{assistant_json}</pre>
912
  </div>
 
 
 
 
913
 
914
  <p class="footer">Cloud Notifier Interface</p>
915
  </div>
@@ -924,6 +956,12 @@ async def root(request: Request):
924
  // Update content
925
  document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
926
  document.getElementById(tabId).classList.add('active');
 
 
 
 
 
 
927
  }}
928
 
929
  // Basic JSON Syntax Highlighter
@@ -955,92 +993,6 @@ async def root(request: Request):
955
  """
956
 
957
 
958
- @app.get("/logs", response_class=HTMLResponse)
959
- async def view_logs():
960
- """Returns the application logs."""
961
- try:
962
- with open("app.log", "r") as f:
963
- lines = f.readlines()
964
- # Show last 1000 lines
965
- log_content = "".join(lines[-1000:])
966
- # Escape HTML to prevent injection if logs contain < >
967
- log_content = log_content.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
968
- except Exception as e:
969
- log_content = f"Error reading logs: {e}"
970
-
971
- return f"""
972
- <!DOCTYPE html>
973
- <html lang="en">
974
- <head>
975
- <meta charset="UTF-8">
976
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
977
- <title>Application Logs</title>
978
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
979
- <style>
980
- body {{
981
- font-family: 'Inter', sans-serif;
982
- background: #0f172a;
983
- color: #f8fafc;
984
- margin: 0;
985
- padding: 20px;
986
- }}
987
- .header {{
988
- display: flex;
989
- justify-content: space-between;
990
- align-items: center;
991
- margin-bottom: 20px;
992
- border-bottom: 1px solid rgba(255, 255, 255, 0.1);
993
- padding-bottom: 10px;
994
- }}
995
- .header h1 {{
996
- margin: 0;
997
- font-size: 1.5rem;
998
- color: #60a5fa;
999
- }}
1000
- .btn-back {{
1001
- background: rgba(255, 255, 255, 0.1);
1002
- color: white;
1003
- text-decoration: none;
1004
- padding: 8px 16px;
1005
- border-radius: 6px;
1006
- font-weight: 600;
1007
- transition: background 0.3s;
1008
- }}
1009
- .btn-back:hover {{
1010
- background: rgba(255, 255, 255, 0.2);
1011
- }}
1012
- .log-container {{
1013
- background: #0d1117;
1014
- border: 1px solid rgba(255, 255, 255, 0.1);
1015
- padding: 15px;
1016
- border-radius: 8px;
1017
- font-family: 'Consolas', 'Monaco', monospace;
1018
- font-size: 0.9rem;
1019
- line-height: 1.5;
1020
- white-space: pre-wrap;
1021
- word-wrap: break-word;
1022
- color: #a5d6ff;
1023
- max-height: 80vh;
1024
- overflow-y: auto;
1025
- }}
1026
- </style>
1027
- </head>
1028
- <body>
1029
- <div class="header">
1030
- <h1>πŸ“œ Application Logs (Last 1000 lines)</h1>
1031
- <a href="/" class="btn-back">&larr; Back to Dashboard</a>
1032
- </div>
1033
- <div class="log-container" id="log-container">{{log_content}}</div>
1034
- <script>
1035
- // Auto-scroll to bottom of the logs
1036
- var logContainer = document.getElementById("log-container");
1037
- logContainer.scrollTop = logContainer.scrollHeight;
1038
- </script>
1039
- </body>
1040
- </html>
1041
- """.replace("{{log_content}}", log_content)
1042
-
1043
-
1044
  @app.get("/assistant")
1045
  async def internal_assistant():
1046
  load_dotenv(override=True)
 
752
  health_data = await health_check()
753
  assistant_data = await internal_assistant()
754
 
755
+ # Fetch logs internally
756
+ try:
757
+ with open("app.log", "r") as f:
758
+ lines = f.readlines()
759
+ # Show last 1000 lines
760
+ log_content = "".join(lines[-1000:])
761
+ # Escape HTML
762
+ log_content = log_content.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
763
+ except Exception as e:
764
+ log_content = f"Error reading logs: {e}"
765
+
766
  # Format nicely as JSON strings
767
  health_json = json.dumps(health_data, indent=2)
768
  assistant_json = json.dumps(assistant_data, indent=2)
 
888
  .null {{ color: #ff7b72; }}
889
  .key {{ color: #7ee787; font-weight: 600; }}
890
 
891
+ /* Logs Container Styling */
892
+ .log-container {{
893
+ background: #0d1117;
894
+ border: 1px solid rgba(255, 255, 255, 0.1);
895
+ padding: 15px;
896
+ border-radius: 8px;
897
+ font-family: 'Consolas', 'Monaco', monospace;
898
+ font-size: 0.9rem;
899
+ line-height: 1.5;
900
+ white-space: pre-wrap;
901
+ word-wrap: break-word;
902
+ color: #a5d6ff;
903
+ max-height: 60vh;
904
+ overflow-y: auto;
905
+ box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
906
+ }}
907
+
908
  @keyframes fadeIn {{
909
  from {{ opacity: 0; transform: translateY(5px); }}
910
  to {{ opacity: 1; transform: translateY(0); }}
 
928
  <div class="tabs">
929
  <button class="tab-btn active" onclick="switchTab('health')">πŸ₯ Health</button>
930
  <button class="tab-btn" onclick="switchTab('assistant')">πŸ€– Assistant</button>
931
+ <button class="tab-btn" onclick="switchTab('logs')">πŸ“œ Logs</button>
932
  </div>
933
 
934
  <div id="health" class="tab-content active">
 
938
  <div id="assistant" class="tab-content">
939
  <pre class="code-block" id="assistant-json">{assistant_json}</pre>
940
  </div>
941
+
942
+ <div id="logs" class="tab-content">
943
+ <div class="log-container" id="log-container-view">{{log_content}}</div>
944
+ </div>
945
 
946
  <p class="footer">Cloud Notifier Interface</p>
947
  </div>
 
956
  // Update content
957
  document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
958
  document.getElementById(tabId).classList.add('active');
959
+
960
+ // Auto-scroll logs when tab is opened
961
+ if (tabId === 'logs') {{
962
+ var logContainer = document.getElementById('log-container-view');
963
+ logContainer.scrollTop = logContainer.scrollHeight;
964
+ }}
965
  }}
966
 
967
  // Basic JSON Syntax Highlighter
 
993
  """
994
 
995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
996
  @app.get("/assistant")
997
  async def internal_assistant():
998
  load_dotenv(override=True)