Browse Source

Use logging instead of cout in main

Nubben 1 year ago
parent
commit
d992e7e2d0
2 changed files with 9 additions and 7 deletions
  1. 1
    1
      cr
  2. 8
    6
      src/main.cpp

+ 1
- 1
cr View File

@@ -2,4 +2,4 @@
2 2
 physicalCpuCount=$([[ $(uname) = 'Darwin' ]] &&
3 3
                        sysctl -n hw.physicalcpu_max ||
4 4
                        lscpu -p | egrep -v '^#' | sort -u -t, -k 2,4 | wc -l)
5
-make -j$physicalCpuCount && ./netrunner http://motherfuckingwebsite.com/
5
+make -j$physicalCpuCount && ./netrunner http://motherfuckingwebsite.com/ -log debug

+ 8
- 6
src/main.cpp View File

@@ -11,6 +11,7 @@
11 11
 #include "WebResource.h"
12 12
 #include "CommandLineParams.h"
13 13
 #include "URL.h"
14
+#include "Log.h"
14 15
 
15 16
 const std::unique_ptr<Window> window = std::make_unique<Window>();
16 17
 URL currentURL;
@@ -20,7 +21,7 @@ bool setWindowContent(URL const& url);
20 21
 bool setWindowContent(URL const& url) {
21 22
     WebResource res = getWebResource(url);
22 23
     if (res.resourceType == ResourceType::INVALID) {
23
-        std::cout << "Invalid resource type: " << res.raw << std::endl;
24
+        logError() << "Invalid resource type: " << res.raw << std::endl;
24 25
         return false;
25 26
     }
26 27
 
@@ -28,15 +29,15 @@ bool setWindowContent(URL const& url) {
28 29
     const std::clock_t begin = clock();
29 30
     std::shared_ptr<Node> rootNode = parser.parse(res.raw);
30 31
     const std::clock_t end = clock();
31
-    std::cout << "Parsed document in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
32
+    logDebug() << "Parsed document in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
32 33
     window->setDOM(rootNode);
33 34
     return true;
34 35
 }
35 36
 
36 37
 void navTo(std::string url) {
37
-    std::cout << "navTo(" << url << ")" << std::endl;
38
+    logDebug() << "navTo(" << url << ")" << std::endl;
38 39
     currentURL = currentURL.merge(URL(url));
39
-    std::cout << "go to: " << currentURL << std::endl;
40
+    logDebug() << "go to: " << currentURL << std::endl;
40 41
     setWindowContent(currentURL);
41 42
 }
42 43
 
@@ -45,14 +46,15 @@ int main(int argc, char *argv[]) {
45 46
         std::cout << "./netrunner <url|file.html>" << std::endl;
46 47
         return 1;
47 48
     }
48
-    initCLParams(argc, argv);
49 49
     std::cout << "/g/ntr - NetRunner build " << __DATE__ << std::endl;
50
+    
51
+    initCLParams(argc, argv);
50 52
     std::string url = getCLParamByIndex(1);
51 53
     if (url[0] == '/') {
52 54
         url = "file://" + url;
53 55
     }
54 56
     currentURL=URL(url);
55
-    std::cout << "loading [" << currentURL << "]" << std::endl;
57
+    logDebug() << "loading [" << currentURL << "]" << std::endl;
56 58
 
57 59
     if (!setWindowContent(currentURL)) {
58 60
         return 1;