cjdnslog 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <http://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. cjdns = connectWithAdminInfo();
  31. level = '';
  32. fileName = '';
  33. line = 0;
  34. args = len(sys.argv) - 1;
  35. if (args == 0):
  36. usage();
  37. exit(0);
  38. if (args > 0): level = sys.argv[1];
  39. if (args > 1): fileName = sys.argv[2];
  40. if (args > 2): line = int(sys.argv[3]);
  41. sub = cjdns.AdminLog_subscribe(line, fileName, level);
  42. if (sub['error'] == 'none'):
  43. recieve(cjdns, sub['txid']);
  44. else:
  45. print(sub);