How to make custom logging in nxweb?

74 views
Skip to first unread message

Amey Jadiye

unread,
Feb 13, 2014, 11:02:41 AM2/13/14
to nx...@googlegroups.com
Hi,

The logging in nx web is certainly very good ,it works in nonblocking manner , its fast ,reliable.
but how to make our own INFO,Debug ,Error logging in nxweb ? also how to rotate the log file on basis of size or time ? Ex. each file of 20Mb or file on each hour ?

Thanks
Amey

Yaroslav

unread,
Feb 13, 2014, 12:03:29 PM2/13/14
to nx...@googlegroups.com
Hi Amey,

Nxweb's access log is designed for speed. Every network thread buffers multiple records in memory, then dumps them into file. It is fast but records from different network threads might come out of order.

Error log (as well as info/debug/etc) is not fast at all. It uses fprintf + file lock/flush for every call. This is not very efficient but simple. You can try similar approach for a start.

For max performance you might want to utilize existing nxweb's access logging mechanism. See access_log.c source. nxweb_access_log_add_frag() method can be used to add custom fields to log record.

Access log can be restarted by sending SIGUSR1 or SIGHUP to nxweb process.

Here is sample logrotate config that I use to rotate my logs daily:

/srv/nxweb/logs/nxweb_*_log {
    rotate 7
    daily
    minsize 1000000
    dateext
    create 664 www www
    compress
    missingok
    notifempty
    sharedscripts
    postrotate
        /sbin/reload nxweb
        sleep 10
    endscript
}

# /sbin/reload nxweb - this command sends SIGHUP to nxweb (I use Upstart to launch nxweb).

Yaroslav



--
You received this message because you are subscribed to the Google Groups "nxweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nxweb+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Amey Jadiye

unread,
Feb 25, 2014, 3:33:51 PM2/25/14
to nx...@googlegroups.com
Ok , i come to know how the access log works in nxweb and it rotation to, but what i f i want to log the information which i am responding ? in short how to create response log in the same manner access log ? from the code what i understand and what i have to do for response  log is  :

  1. create another functions for logging custom log like listed below.
  • void nxweb_access_log_restart(); // specify access log file path in nxweb_server_config.access_log_fpath
  • void nxweb_access_log_stop();
  • void nxweb_access_log_thread_flush(); // flush net_thread's access log
  • void nxweb_access_log_add_frag(nxweb_http_request* req, nxweb_log_fragment* frag); // collect info to log
  • void nxweb_access_log_write(nxweb_http_request* req); // write request's log record to thread's buffer
  • void nxweb_access_log_on_request_received(nxweb_http_server_connection* conn, nxweb_http_request* req);
  • void nxweb_access_log_on_request_complete(nxweb_http_server_connection* conn, nxweb_http_request* req, nxweb_http_response* resp)
      2. then create custom log fragment structure, just like nxweb_http_request
      3. do some configuration changes like log file name etc..
      4. call functions within your custom modules, to add new fragment to log in to file

please let me know whether i am wrong ?

Regards,
Amey  

Yaroslav

unread,
Feb 25, 2014, 3:57:29 PM2/25/14
to nx...@googlegroups.com
Hi Amey,

Do you really need a separate response log? I think you can add your info to common access log, then filter it out by post-processing common access log file. This will save you a lot of work.

Yaroslav


--

Amey Jadiye

unread,
Feb 25, 2014, 4:11:43 PM2/25/14
to nx...@googlegroups.com
Okey 
thats what i think first time but currently i am generating around 2Gb access log file per hour , and response+accesslog will be going around 3-4Gb, i want to save that post processing , currently i dont need the access log and need response log , so my plan was to disable access log and start custom response log.

so modification is necessary for me , your guidance will be valuable for me.

one more thing to ask ,access logging is done after flow comes to module or before ?

Thanks in advance.


Amey


--
You received this message because you are subscribed to a topic in the Google Groups "nxweb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nxweb/79MvPviJ2rg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nxweb+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--

,Thanks

_____________________

Amey Jadiye

(+91 73 87 770 382)


Yaroslav

unread,
Feb 25, 2014, 4:22:18 PM2/25/14
to nx...@googlegroups.com
All access logging is done inside access_log.c via nxweb_access_log_add_frag() function (called from BUILD_FRAG_END macro).

Different callbacks get called during different stages of request processing:

nxweb_access_log_on_request_received()
nxweb_access_log_on_request_complete()
nxweb_access_log_on_proxy_response()

You can modify these callbacks to exclude unnecessary information from access log.

Reply all
Reply to author
Forward
0 new messages