You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "rm5248 (via GitHub)" <gi...@apache.org> on 2023/05/20 22:58:27 UTC

[GitHub] [logging-log4cxx] rm5248 opened a new issue, #214: Hexdump logging feature

rm5248 opened a new issue, #214:
URL: https://github.com/apache/logging-log4cxx/issues/214

   Since I do a lot of low-level code, it would be very convenient to have a function of some kind that can log data in a hexdump format.  That way, I can pass it either a C array or a `std::vector` in order to dump the data in a readable manner.
   
   Hexdump output for reference:
   ```
   robert@debian:~/logging-log4cxx$ hd LICENSE 
   00000000  0a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
   00000010  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
   00000020  20 20 41 70 61 63 68 65  20 4c 69 63 65 6e 73 65  |  Apache License|
   00000030  0a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
   00000040  20 20 20 20 20 20 20 20  20 20 20 20 56 65 72 73  |            Vers|
   00000050  69 6f 6e 20 32 2e 30 2c  20 4a 61 6e 75 61 72 79  |ion 2.0, January|
   00000060  20 32 30 30 34 0a 20 20  20 20 20 20 20 20 20 20  | 2004.          |
   00000070  20 20 20 20 20 20 20 20  20 20 20 20 20 20 68 74  |              ht|
   ```
   
   idea for API:
   ```
   void logArray(LoggerPtr, LevelPtr, LogString prefix, void* data, size_t data_len)
   
   example output:
   com.foo.bar INFO - prefix string:
   00000000  0a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               | 
   ...
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [logging-log4cxx] swebb2066 commented on issue #214: Hexdump logging feature

Posted by "swebb2066 (via GitHub)" <gi...@apache.org>.
swebb2066 commented on issue #214:
URL: https://github.com/apache/logging-log4cxx/issues/214#issuecomment-1556066160

   What about using a template? For example:
   ```
   /// Streamable array elements
   template <typename T, typename S, typename D = T>
   class SeparatedArray
   {
       const T *m_vec;
       size_t m_len;
       S m_separator;
       size_t m_perLine;
   public:
       SeparatedArray(const T *vec, size_t len, S separ, size_t perLine = 10)
           : m_vec(vec)
           , m_len(len)
           , m_separator(separ)
           , m_perLine(perLine)
       {}
       void Write(std::ostream& os) const
       {
           if (0 < m_perLine && m_perLine <= m_len)
               os << std::endl;
           for (size_t i = 0; i < m_len; ++i)
           {
               if (0 < i)
               {
                   if (0 < m_perLine && 0 == (i % m_perLine))
                       os << std::endl;
                   else
                       os << m_separator;
               }
               os << (D)m_vec[i];
           }
       }
   };
   
   /// Put \c S separated type \c D elements of \c v onto \c os
       template <typename T, typename S, typename D>
       std::ostream&
    operator<<(std::ostream& os, const SeparatedArray<T, S, D>& v)
   { v.Write(os); return os;  }
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [logging-log4cxx] rm5248 closed issue #214: Hexdump logging feature

Posted by "rm5248 (via GitHub)" <gi...@apache.org>.
rm5248 closed issue #214: Hexdump logging feature
URL: https://github.com/apache/logging-log4cxx/issues/214


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org