Rewrite of logger.js with cleaner implementation

No longer creates tcp server and udp socket on require.
Move most inline functions into global scope to prevent
recreating the functions on each run