Advertisement
Stiepen

log.cpp

Apr 18th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <syslog.h>
  2. #include <iostream>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6. int main(int argc, char *argv[])
  7. {
  8.     int stuff = 0;
  9.     if (argc != 3 && argc != 4) {
  10.         cout << "Usage: log <priority> <prog> <line>" << endl;
  11.         return -1;
  12.     }
  13.     setlogmask (LOG_UPTO (LOG_DEBUG));
  14.     openlog (argv[2], LOG_CONS | LOG_NDELAY, /*atoi (argv[2]) * 8*/ LOG_LOCAL1);
  15.    
  16.     if (argc == 4) {
  17.         syslog(atoi(argv[1]), argv[3]);  // argv[4]
  18.     } else {
  19.         string line;
  20.         while (getline(cin, line)) {
  21.             syslog(atoi(argv[1]), line.c_str());
  22.         }
  23.     }
  24.  
  25.     closelog();
  26.  
  27.     return 0;
  28. }
  29. // compile with g++ -o log log.cpp
  30. // chmod +x log
  31. // ./log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement