1
0

cjdnslog 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python2
  2. # You may redistribute this program and/or modify it under the terms of
  3. # the GNU General Public License as published by the Free Software Foundation,
  4. # either version 3 of the License, or (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;
  14. from cjdnsadmin.bencode import *;
  15. import sys;
  16. def usage():
  17. app = sys.argv[0];
  18. print("Usage: " + app + " <level> <fileName> <lineNum>");
  19. print(app + " 'INFO' <-- log all INFO and higher (WARN, ERROR, or CRITICAL) messages.");
  20. print(app + " '' <-- log everything");
  21. print(app + " '' 'CryptoAuth.c' <-- log everything in CryptoAuth.c");
  22. print(app + " 'INFO' 'CryptoAuth.c' <-- log INFO and higher in CryptoAuth.c");
  23. print(app + " '' 'CryptoAuth.c' 747 <-- print messages from log statement on line 747 of CryptoAuth.c");
  24. print(app + " '' '' 747 <-- print messages from log statements on line 747 of any file at all.");
  25. def doLog(data):
  26. print str(data['time']) + ' ' + data['level'] + ' ' + data['file'] + ':' + str(data['line']) + ' ' + data['message'];
  27. def recieve(cjdns, txid):
  28. while True:
  29. doLog(cjdns.getMessage(txid));
  30. def main():
  31. cjdns = connectWithAdminInfo();
  32. level = '';
  33. fileName = '';
  34. line = 0;
  35. args = len(sys.argv) - 1;
  36. if (args == 0):
  37. usage();
  38. exit(0);
  39. if (args > 0): level = sys.argv[1];
  40. if (args > 1): fileName = sys.argv[2];
  41. if (args > 2): line = int(sys.argv[3]);
  42. sub = cjdns.AdminLog_subscribe(line, fileName, level);
  43. if (sub['error'] == 'none'):
  44. recieve(cjdns, sub['txid']);
  45. else:
  46. print(sub);
  47. try:
  48. main()
  49. except KeyboardInterrupt:
  50. print("")
  51. print("Interrupted by user.")