Artem Senichev | e8837d5 | 2020-06-07 11:59:04 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2020 YADRO |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <zlib.h> |
| 7 | |
| 8 | #include <ctime> |
| 9 | #include <string> |
| 10 | |
| 11 | /** |
| 12 | * @class ZlibFile |
| 13 | * @brief Log file writer. |
| 14 | */ |
| 15 | class ZlibFile |
| 16 | { |
| 17 | public: |
| 18 | /** |
| 19 | * @brief Constructor create new file for writing logs. |
| 20 | * |
| 21 | * @param[in] fileName path to the file |
| 22 | * |
| 23 | * @throw ZlibException in case of errors |
| 24 | */ |
| 25 | ZlibFile(const std::string& fileName); |
| 26 | |
| 27 | ~ZlibFile(); |
| 28 | |
| 29 | ZlibFile(const ZlibFile&) = delete; |
| 30 | ZlibFile& operator=(const ZlibFile&) = delete; |
| 31 | |
| 32 | /** |
| 33 | * @brief Close file. |
| 34 | * |
| 35 | * @throw ZlibException in case of errors |
| 36 | */ |
| 37 | void close(); |
| 38 | |
| 39 | /** |
| 40 | * @brief Write single log message to the file. |
| 41 | * |
| 42 | * @param[in] timeStamp time stamp of the log message |
| 43 | * @param[in] message log message text |
| 44 | * |
| 45 | * @throw ZlibException in case of errors |
| 46 | */ |
| 47 | void write(const tm& timeStamp, const std::string& message) const; |
| 48 | |
| 49 | private: |
| 50 | /** @brief File name. */ |
| 51 | std::string fileName; |
| 52 | /** @brief zLib file descriptor. */ |
| 53 | gzFile fd; |
| 54 | }; |