SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Logger.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_fs_Logger_h
7 #define swcdb_fs_Logger_h
8 
9 
10 // used-locally
11 
12 #define _SWC_FS_ERR(_error, _cmd, _tracker, _code) \
13  SWC_LOG_OUT( \
14  ((_error) ? LOG_ERROR : LOG_DEBUG), \
15  SWC_LOG_OSTREAM << _cmd; \
16  if(_error) Error::print(SWC_LOG_OSTREAM << ' ', _error); \
17  _code; \
18  ); _tracker.stop(_error);
19 
20 
21 #define _SWC_FS_FD_ERR(_error, _cmd, _smartfd, _tracker, _code) \
22  _SWC_FS_ERR(_error, _cmd, _tracker, \
23  _code; \
24  _smartfd->print(SWC_LOG_OSTREAM << ' '); \
25  );
26 
27 
28 
29 // paths based
30 
31 #define SWC_FS_EXISTS_START(_path) \
32  SWC_LOG_OUT(LOG_DEBUG, \
33  SWC_LOG_OSTREAM << "exists path='" << _path << '\''; \
34  );
35 
36 #define SWC_FS_EXISTS_FINISH(_error, _path, _state, _tracker) \
37  _SWC_FS_ERR(_error, "exists", _tracker, \
38  SWC_LOG_OSTREAM << " state=" << _state << " path='" << _path << '\''; \
39  );
40 
41 
42 
43 #define SWC_FS_REMOVE_START(_path) \
44  SWC_LOG_OUT(LOG_DEBUG, \
45  SWC_LOG_OSTREAM << "remove path='" << _path << '\''; \
46  );
47 
48 #define SWC_FS_REMOVE_FINISH(_error, _path, _tracker) \
49  _SWC_FS_ERR(_error, "remove", _tracker, \
50  SWC_LOG_OSTREAM << " path='" << _path << '\''; \
51  );
52 
53 
54 
55 #define SWC_FS_LENGTH_START(_path) \
56  SWC_LOG_OUT(LOG_DEBUG, \
57  SWC_LOG_OSTREAM << "length path='" << _path << '\''; \
58  );
59 
60 #define SWC_FS_LENGTH_FINISH(_error, _path, _len, _tracker) \
61  _SWC_FS_ERR(_error, "length", _tracker, \
62  SWC_LOG_OSTREAM << " len=" << _len << " path='" << _path << '\''; \
63  );
64 
65 
66 
67 #define SWC_FS_MKDIRS_START(_path) \
68  SWC_LOG_OUT(LOG_DEBUG, \
69  SWC_LOG_OSTREAM << "mkdirs path='" << _path << '\''; \
70  );
71 
72 #define SWC_FS_MKDIRS_FINISH(_error, _path, _tracker) \
73  _SWC_FS_ERR(_error, "mkdirs", _tracker, \
74  SWC_LOG_OSTREAM << " path='" << _path << '\''; \
75  );
76 
77 
78 
79 #define SWC_FS_READDIR_START(_path) \
80  SWC_LOG_OUT(LOG_DEBUG, \
81  SWC_LOG_OSTREAM << "readdir path='" << _path << '\''; \
82  );
83 
84 #define SWC_FS_READDIR_FINISH(_error, _path, _sz, _tracker) \
85  _SWC_FS_ERR(_error, "readdir", _tracker, \
86  SWC_LOG_OSTREAM << " sz=" << _sz << " path='" << _path << '\''; \
87  );
88 
89 
90 
91 #define SWC_FS_RMDIR_START(_path) \
92  SWC_LOG_OUT(LOG_DEBUG, \
93  SWC_LOG_OSTREAM << "rmdir path='" << _path << '\''; \
94  );
95 
96 #define SWC_FS_RMDIR_FINISH(_error, _path, _tracker) \
97  _SWC_FS_ERR(_error, "rmdir", _tracker, \
98  SWC_LOG_OSTREAM << " path='" << _path << '\''; \
99  );
100 
101 
102 
103 #define SWC_FS_RENAME_START(_from, _to) \
104  SWC_LOG_OUT(LOG_DEBUG, \
105  SWC_LOG_OSTREAM << "rename '" << _from << "' to '" << _to << '\''; \
106  );
107 
108 #define SWC_FS_RENAME_FINISH(_error, _from, _to, _tracker) \
109  _SWC_FS_ERR(_error, "rename", _tracker, \
110  SWC_LOG_OSTREAM << " '" << _from << "' to '" << _to << '\''; \
111  );
112 
113 
114 
115 #define SWC_FS_READALL_START(_name) \
116  SWC_LOG_OUT(LOG_DEBUG, \
117  SWC_LOG_OSTREAM << "readall file='" << _name << '\''; \
118  );
119 
120 #define SWC_FS_READALL_FINISH(_error, _name, _amount, _tracker) \
121  _SWC_FS_ERR(_error == Error::FS_PATH_NOT_FOUND ? Error::OK : _error, \
122  "readall", _tracker, \
123  SWC_LOG_OSTREAM << " file='" << _name << "' amt=" << _amount; \
124  );
125 
126 
127 
128 // SmartFd based
129 
130 
131 #define SWC_FS_CREATE_START(_smartfd, _replication) \
132  SWC_LOG_OUT(LOG_DEBUG, \
133  _smartfd->print( \
134  SWC_LOG_OSTREAM << "create replicas=" << int(_replication) << ' '); \
135  );
136 
137 #define SWC_FS_CREATE_FINISH(_error, _smartfd, _open_fds, _tracker) \
138  _SWC_FS_FD_ERR(_error, "create", _smartfd, _tracker, \
139  SWC_LOG_OSTREAM << " open-fds=" << _open_fds; \
140  );
141 
142 
143 
144 #define SWC_FS_OPEN_START(_smartfd) \
145  SWC_LOG_OUT(LOG_DEBUG, \
146  _smartfd->print(SWC_LOG_OSTREAM << "open "); \
147  );
148 
149 #define SWC_FS_OPEN_FINISH(_error, _smartfd, _open_fds, _tracker) \
150  _SWC_FS_FD_ERR(_error, "open", _smartfd, _tracker, \
151  SWC_LOG_OSTREAM << " open-fds=" << _open_fds; \
152  );
153 
154 
155 
156 #define SWC_FS_WRITE_START(_smartfd, _replication, _amount) \
157  SWC_LOG_OUT(LOG_DEBUG, \
158  _smartfd->print( \
159  SWC_LOG_OSTREAM << "write replicas=" << int(_replication) \
160  << " amt=" << _amount << ' '); \
161  );
162 
163 #define SWC_FS_WRITE_FINISH(_error, _smartfd, _tracker) \
164  _SWC_FS_ERR(_error, "write", _tracker, \
165  _smartfd->print(SWC_LOG_OSTREAM << ' '); \
166  );
167 
168 
169 
170 #define SWC_FS_READ_START(_smartfd, _amount) \
171  SWC_LOG_OUT(LOG_DEBUG, \
172  _smartfd->print(SWC_LOG_OSTREAM << "read amt=" << _amount << ' '); \
173  );
174 
175 #define SWC_FS_READ_FINISH(_error, _smartfd, _amount, _tracker) \
176  _SWC_FS_FD_ERR( \
177  _error && _error == Error::FS_EOF ? Error::OK : _error, \
178  "read", _smartfd, _tracker, \
179  SWC_LOG_OSTREAM << " amt=" << _amount; \
180  if(_error == Error::FS_EOF) SWC_LOG_OSTREAM << "EOF"; \
181  );
182 
183 
184 
185 #define SWC_FS_PREAD_START(_smartfd, _offset, _amount) \
186  SWC_LOG_OUT(LOG_DEBUG, \
187  _smartfd->print(SWC_LOG_OSTREAM \
188  << "pread offset=" << _offset << " amt=" << _amount << ' '); \
189  );
190 
191 #define SWC_FS_PREAD_FINISH(_error, _smartfd, _amount, _tracker) \
192  _SWC_FS_FD_ERR( \
193  _error && _error == Error::FS_EOF ? Error::OK : _error, \
194  "pread", _smartfd, _tracker, \
195  SWC_LOG_OSTREAM << " amt=" << _amount; \
196  if(_error == Error::FS_EOF) SWC_LOG_OSTREAM << "EOF"; \
197  );
198 
199 
200 
201 #define SWC_FS_COMBI_PREAD_START(_smartfd, _offset, _amount) \
202  SWC_LOG_OUT(LOG_DEBUG, \
203  _smartfd->print(SWC_LOG_OSTREAM \
204  << "combi-pread offset=" << _offset << " amt=" << _amount << ' '); \
205  );
206 
207 #define SWC_FS_COMBI_PREAD_FINISH(_error, _smartfd, _amount, _tracker) \
208  _SWC_FS_FD_ERR( \
209  _error && _error == Error::FS_EOF ? Error::OK : _error, \
210  "combi-pread", _smartfd, _tracker, \
211  SWC_LOG_OSTREAM << " amt=" << _amount; \
212  if(_error == Error::FS_EOF) SWC_LOG_OSTREAM << "EOF"; \
213  );
214 
215 
216 
217 #define SWC_FS_APPEND_START(_smartfd, _amount, _flags) \
218  SWC_LOG_OUT(LOG_DEBUG, \
219  _smartfd->print(SWC_LOG_OSTREAM \
220  << "append amt=" << _amount << " flags=" << int(_flags) << ' '); \
221  );
222 
223 #define SWC_FS_APPEND_FINISH(_error, _smartfd, _amount, _tracker) \
224  _SWC_FS_FD_ERR(_error, "append", _smartfd, _tracker, \
225  SWC_LOG_OSTREAM << " amt=" << _amount; \
226  );
227 
228 
229 
230 #define SWC_FS_SEEK_START(_smartfd, _offset) \
231  SWC_LOG_OUT(LOG_DEBUG, \
232  _smartfd->print(SWC_LOG_OSTREAM << "seek offset=" << _offset << ' '); \
233  );
234 
235 #define SWC_FS_SEEK_FINISH(_error, _smartfd, _tracker) \
236  _SWC_FS_FD_ERR(_error, "seek", _smartfd, _tracker, );
237 
238 
239 
240 
241 #define SWC_FS_FLUSH_START(_smartfd) \
242  SWC_LOG_OUT(LOG_DEBUG, \
243  _smartfd->print(SWC_LOG_OSTREAM << "flush "); \
244  );
245 
246 #define SWC_FS_FLUSH_FINISH(_error, _smartfd, _tracker) \
247  _SWC_FS_FD_ERR(_error, "flush", _smartfd, _tracker, );
248 
249 
250 
251 
252 #define SWC_FS_SYNC_START(_smartfd) \
253  SWC_LOG_OUT(LOG_DEBUG, \
254  _smartfd->print(SWC_LOG_OSTREAM << "sync "); \
255  );
256 
257 #define SWC_FS_SYNC_FINISH(_error, _smartfd, _tracker) \
258  _SWC_FS_FD_ERR(_error, "sync", _smartfd, _tracker, );
259 
260 
261 
262 
263 #define SWC_FS_CLOSE_START(_smartfd) \
264  SWC_LOG_OUT(LOG_DEBUG, \
265  _smartfd->print(SWC_LOG_OSTREAM << "close "); \
266  );
267 
268 #define SWC_FS_CLOSE_FINISH(_error, _smartfd, _tracker) \
269  _SWC_FS_FD_ERR(_error, "close", _smartfd, _tracker, );
270 
271 
272 
273 
274 #endif // swcdb_fs_Logger_h