Browse Source

修复部分问题

NH 1 year ago
parent
commit
09131638d7
4 changed files with 12 additions and 3 deletions
  1. 2 0
      include/util/system.h
  2. 2 1
      src/base/environment.cpp
  3. 7 2
      src/base/log4.cpp
  4. 1 0
      src/util/file.cpp

+ 2 - 0
include/util/system.h

@@ -11,6 +11,8 @@ namespace ylib
 		int64 random(int64 min, int64 max);
 		//取运行目录
 		std::string current_dir();
+		//取EXE目录
+		std::string application_dir();
 		//取运行全路径
 		std::string current_filepath();
 		//取临时目录

+ 2 - 1
src/base/environment.cpp

@@ -16,8 +16,9 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
 */
 
 #include "base/environment.h"
+#include "util/system.h"
 namespace ylib
 {
     extern ylib::environment *env = new ylib::environment();
-    extern ylib::log4 *log = new ylib::log4("./log/log.log");
+    extern ylib::log4* log = nullptr;
 }

+ 7 - 2
src/base/log4.cpp

@@ -56,6 +56,7 @@ ylib::log4::log4(const std::string& filepath)
     APPENDER_CONSOLE->setLayout(std::unique_ptr<log4cplus::Layout>(new log4cplus::PatternLayout("%D{%Y-%m-%d %H:%M:%S.%q} [%-5p] [%c] -  %m %n")));
 #else
     m_appender = new ylib::file_io;
+    ((ylib::file_io*)m_appender)->open(filepath);
 #endif
 
 }
@@ -78,8 +79,12 @@ inline void append_log(const char* name,const std::string& value)
 inline void append_log(void* appender, const std::string& type, const std::string& name, const std::string& value)
 {
     auto file = (ylib::file_io*)appender;
-    std::string content = "[" + time::now_time() + "][" + name + "][" + type + "]: " + value;
-    file->appead(content.c_str(),content.length());
+    if (file->is_open())
+    {
+        std::string content = "[" + time::now_time() + "][" + name + "][" + type + "]: " + value;
+        file->appead(content.c_str(), content.length());
+    }
+    
 }
 #endif
 ylib::log4& ylib::log4::warn(const std::string& value,const std::string& name)

+ 1 - 0
src/util/file.cpp

@@ -167,6 +167,7 @@ bool ylib::file_io::read(int64 size, buffer &data)
 
 void ylib::file_io::jump(int64 offset, std::ios_base::seekdir way)
 {
+
     // 清楚所有错误状态
     m_stream->clear();
     // 根据提供的方向参数way来确定如何应用偏移量offset