PILog works

This commit is contained in:
2024-09-13 23:05:24 +03:00
parent 9a352bfc83
commit 7a945f47b1
3 changed files with 168 additions and 14 deletions

View File

@@ -41,26 +41,78 @@ public:
PILog();
~PILog();
//! \~english Returns prefix for filename.
PIString applicationName() const { return app_name; }
//! \~english Set prefix for filename. Should be set \b before \a setDir()!
void setApplicationName(const PIString & n) { app_name = n; }
//! \~english Returns directory for log files.
PIString dir() const { return log_dir; }
//! \~english Set directory for log files. Should be set \b after \a setApplicationName()!
void setDir(const PIString & d);
PISystemTime splitTime() const { return split_time; }
void setSplitTime(PISystemTime st) { split_time = st; }
void enqueue(const PIString & msg);
//! \~english Returns lifetime for file.
PISystemTime fileSplitTime() const { return split_time; }
//! \~english Set lifetime for file. Each "st" interval new file will be created.
void setFileSplitTime(PISystemTime st) { split_time = st; }
//! \~english Returns timestamp format for line.
PIString timestampFormat() const { return timestamp_format; }
//! \~english Set timestamp format for line. Default is "yyyy-MM-dd hh:mm:ss.zzz".
void setTimestampFormat(const PIString & f) { timestamp_format = f; }
//! \~english Returns line format.
PIString lineFormat() const { return line_format; }
//! \~english Set line format. "t" is timestamp, "c" is category and "m" is message. Default is "t - c: m".
void setLineFormat(const PIString & f);
PICout debug(PIObject * context = nullptr);
PICout warning(PIObject * context = nullptr);
PICout error(PIObject * context = nullptr);
//! \~english Write all queued lines and stop. Also called in destructor.
void stop();
private:
enum class Category {
Debug,
Warning,
Error
};
EVENT_HANDLER2(void, coutDone, int, id, PIString *, buff);
PICout makePICout(PIObject * context, Category cat);
void enqueue(const PIString & msg, Category cat = Category::Debug);
struct Entry {
Category cat;
PIDateTime time;
PIString msg;
};
PIString entryToString(const Entry & e) const;
void newFile();
void run() override;
PIMutex log_mutex;
PIMutex log_mutex, cout_mutex;
PIFile log_file;
PIIOTextStream log_ts;
PITimeMeasurer split_tm;
PISystemTime split_time;
PIString log_dir;
PIQueue<PIString> queue;
int part_number = -1;
PIString log_dir, timestamp_format, line_format, line_format_p, app_name;
PIQueue<Entry> queue;
PIMap<int, Category> cout_cat_by_id;
int part_number = -1, cout_id = -1;
};
#endif