nlog.h 813 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef HV_NLOG_H_
  2. #define HV_NLOG_H_
  3. // nlog: extend hlog use hloop
  4. /* you can recv log by:
  5. * Windows: telnet ip port
  6. * Linux: nc ip port
  7. */
  8. /*
  9. * @see examples/hloop_test.c
  10. #include "hlog.h"
  11. #include "nlog.h"
  12. void timer_write_log(htimer_t* timer) {
  13. static int cnt = 0;
  14. hlogi("[%d] Do you recv me?", ++cnt);
  15. }
  16. int main() {
  17. hloop_t* loop = hloop_new(0);
  18. hlog_set_logger(network_logger);
  19. nlog_listen(loop, DEFAULT_LOG_PORT);
  20. htimer_add(loop, timer_write_log, 1000, INFINITE);
  21. hloop_run(loop);
  22. hloop_free(&loop);
  23. }
  24. */
  25. #include "hexport.h"
  26. #include "hloop.h"
  27. #define DEFAULT_LOG_PORT 10514
  28. BEGIN_EXTERN_C
  29. HV_EXPORT void network_logger(int loglevel, const char* buf, int len);
  30. HV_EXPORT hio_t* nlog_listen(hloop_t* loop, int port);
  31. END_EXTERN_C
  32. #endif // HV_NLOG_H_