Add print in console option
This commit is contained in:
		
							parent
							
								
									993869bbc3
								
							
						
					
					
						commit
						8ac79b5a5d
					
				
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							| @ -3,6 +3,7 @@ | ||||
|         "iostream": "cpp", | ||||
|         "iosfwd": "cpp", | ||||
|         "fstream": "cpp", | ||||
|         "*.tcc": "cpp" | ||||
|         "*.tcc": "cpp", | ||||
|         "ostream": "cpp" | ||||
|     } | ||||
| } | ||||
							
								
								
									
										5
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| 
 | ||||
| # A simple Logging library for C++ | ||||
| 
 | ||||
| Logging errors to a file, daily file rotation, date and time stamps. Configurable record structure etc.  | ||||
| 
 | ||||
| @ -14,12 +14,13 @@ class log { | ||||
|     public: | ||||
|     string dir; | ||||
|     bool isKeepOpen; | ||||
|     bool printInConsole; | ||||
|     ofstream logfile; | ||||
|     struct tm * moment; | ||||
|     uint day; | ||||
|     string path; | ||||
| 
 | ||||
|     log (string _dir, bool _isKeepOpen = true); | ||||
|     log (string _dir, bool _isKeepOpen = true, bool _printInConsole = false); | ||||
| 
 | ||||
|     bool isdir(); | ||||
|     bool open(); | ||||
|  | ||||
| @ -1,8 +1,9 @@ | ||||
| #include "../lib/log.hpp" | ||||
| 
 | ||||
| log::log(string _dir, bool _isKeepOpen) { | ||||
| log::log(string _dir, bool _isKeepOpen, bool _printInConsole = false) { | ||||
|    dir = _dir; | ||||
|    isKeepOpen = _isKeepOpen; | ||||
|    printInConsole = _printInConsole; | ||||
| 
 | ||||
|    if (!isdir()) { | ||||
|       cout << "Eror log dir path invalid!" << endl; | ||||
| @ -44,6 +45,10 @@ void log::setMoment() { | ||||
| } | ||||
| 
 | ||||
| void log::put(string logline) { | ||||
|    if (printInConsole) { | ||||
|       cout << logline << endl; | ||||
|    } | ||||
| 
 | ||||
|    setMoment(); | ||||
|    setPrefix(logline); | ||||
| 
 | ||||
| @ -68,10 +73,8 @@ void log::put(string logline) { | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    cout << logline << endl; | ||||
|    logfile << logline << endl; | ||||
| 
 | ||||
| 
 | ||||
|    if (!isKeepOpen && logfile.is_open()) { | ||||
|       loose(); | ||||
|    } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user