| 63 | } |
| 64 | |
| 65 | int EventOutput::json() const |
| 66 | { |
| 67 | JSONFormatter jf(true); |
| 68 | std::ofstream out_file(path.c_str(), std::ofstream::out); |
| 69 | jf.open_array_section("journal"); |
| 70 | { |
| 71 | for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) { |
| 72 | if (auto& le = i->second.log_event; le) { |
| 73 | jf.open_object_section("log_event"); |
| 74 | le->dump(&jf); |
| 75 | jf.close_section(); // log_event |
| 76 | } else if (auto& pi = i->second.pi; pi) { |
| 77 | jf.open_object_section("purge_action"); |
| 78 | pi->dump(&jf); |
| 79 | jf.close_section(); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | jf.close_section(); // journal |
| 84 | jf.flush(out_file); |
| 85 | out_file.close(); |
| 86 | |
| 87 | if (out_file.fail()) { |
| 88 | return -EIO; |
| 89 | } else { |
| 90 | std::cerr << "Wrote output to JSON file '" << path << "'" << std::endl; |
| 91 | return 0; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void EventOutput::list() const |
| 96 | { |