| 29 | using namespace NanoLog::LogLevels; |
| 30 | |
| 31 | int main(int argc, char** argv) { |
| 32 | // Number of messages to log repeatedly and take the average latency |
| 33 | const uint64_t RECORDS = 1000; |
| 34 | |
| 35 | std::chrono::high_resolution_clock::time_point start, stop; |
| 36 | double time_span; |
| 37 | |
| 38 | // Optional: Set the output location for the NanoLog system. By default |
| 39 | // the log will be output to ./compressedLog |
| 40 | NanoLog::setLogFile("/tmp/logFile"); |
| 41 | |
| 42 | // Optional optimization: pre-allocates thread-local data structures |
| 43 | // needed by NanoLog. This can be invoked once per new |
| 44 | // thread that will use the NanoLog system. |
| 45 | NanoLog::preallocate(); |
| 46 | |
| 47 | // Optional: Set the minimum LogLevel that log messages must have to be |
| 48 | // persisted. Valid from least to greatest values are |
| 49 | // DEBUG, NOTICE, WARNING, ERROR |
| 50 | NanoLog::setLogLevel(NOTICE); |
| 51 | |
| 52 | NANO_LOG(DEBUG, "This message wont be logged since it is lower " |
| 53 | "than the current log level."); |
| 54 | |
| 55 | // Log levels can be named explicitly if one does not import the LogLevels |
| 56 | // namespace with 'using' |
| 57 | NANO_LOG(NanoLog::DEBUG, "Another message."); |
| 58 | |
| 59 | start = std::chrono::high_resolution_clock::now(); |
| 60 | for (int i = 0; i < RECORDS; ++i) { |
| 61 | NANO_LOG(NOTICE, "Simple log message with 0 parameters"); |
| 62 | } |
| 63 | stop = std::chrono::high_resolution_clock::now(); |
| 64 | |
| 65 | time_span = std::chrono::duration_cast<std::chrono::duration<double>>( |
| 66 | stop - start).count(); |
| 67 | printf("The total time spent invoking NANO_LOG with no parameters %lu " |
| 68 | "times took %0.2lf seconds (%0.2lf ns/message average)\r\n", |
| 69 | RECORDS, time_span, (time_span/RECORDS)*1e9); |
| 70 | |
| 71 | start = std::chrono::high_resolution_clock::now(); |
| 72 | // Flush all pending log messages to disk |
| 73 | NanoLog::sync(); |
| 74 | stop = std::chrono::high_resolution_clock::now(); |
| 75 | |
| 76 | time_span = std::chrono::duration_cast<std::chrono::duration<double>>( |
| 77 | stop - start).count(); |
| 78 | printf("Flushing the log statements to disk took an additional " |
| 79 | "%0.2lf secs\r\n", time_span); |
| 80 | |
| 81 | // Prints various statistics gathered by the NanoLog system to stdout |
| 82 | printf("%s", NanoLog::getStats().c_str()); |
| 83 | NanoLog::printConfig(); |
| 84 | } |
| 85 |
nothing calls this directly
no test coverage detected