/// <summary> static void rtmp_log_default(int level, const char *format, va_list vl) </summary> private static void rtmp_log_default(RTMP_LogLevel level, string fmt, params object[] vals) { var msg = string.Format(fmt, vals); /* Filter out 'no-name' */ if (RTMP_debuglevel < RTMP_LogLevel.RTMP_LOGALL && msg.Contains("no-name")) { return; } if (fmsg == null) { fmsg = Console.Error; } if (level <= RTMP_debuglevel) { if (needNewLine) { fmsg.WriteLine(); needNewLine = false; } fmsg.WriteLine("{0}: {1}", loglevel_to_string(level), msg); } }
/// <summary> static const char *levels[] = { "CRIT", "ERROR", "WARNING", "INFO", "DEBUG", "DEBUG2" }; </summary> private static string loglevel_to_string(RTMP_LogLevel level) { switch (level) { case RTMP_LogLevel.RTMP_LOGCRIT: return("CRIT"); case RTMP_LogLevel.RTMP_LOGERROR: return("ERROR"); case RTMP_LogLevel.RTMP_LOGWARNING: return("WARNING"); case RTMP_LogLevel.RTMP_LOGINFO: return("INFO"); case RTMP_LogLevel.RTMP_LOGDEBUG: return("DEBUG"); case RTMP_LogLevel.RTMP_LOGDEBUG2: return("DEBUG2"); default: return(string.Empty); } }
/// <summary> void RTMP_LogHex(int level, const uint8_t *data, unsigned long len) </summary> public static void RTMP_LogHex(RTMP_LogLevel level, byte[] data, ulong len) { if (level > RTMP_debuglevel) { return; } var line = string.Empty; var i = 0ul; for (; i < len; ++i) { line += string.Format("{0:x2}", data[i]); if (i != 0 && i % 16 == 0) { RTMP_Log(level, "{0}", line); line = string.Empty; } else { line += " "; } } if (i % 16 != 0) { RTMP_Log(level, "{0}", line); } }
/// <summary> void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len) </summary> public static void RTMP_LogHexString(RTMP_LogLevel level, byte[] data, ulong len) { if (data.Length == 0 || level > RTMP_debuglevel) { return; } /* * data = {'a','b','c',' ','1','2','3','4',' ','1','2','3','4',' ','1','2','3','4',' ','1','2','3','4','\r', '\n' }; * INFO: 0000: 61 62 63 20 31 32 33 34 20 31 32 33 34 20 31 32 abc 1234 1234 12 * INFO: 0010: 33 34 20 31 32 33 34 0a 0d 34 1234.. */ for (var off = 0ul; off < len; off += 16) { var end = false; var dump1 = string.Empty; for (var i = 0u; i < 8; ++i) { if (off + i >= len) { end = true; break; } dump1 += string.Format("{0:x2} ", data[off + i]); } var dump2 = string.Empty; if (!end) { for (var i = 0u; i < 8; ++i) { if (off + i + 8 >= len) { break; } dump2 += string.Format("{0:x2} ", data[off + i + 8]); } } var printable = string.Empty; for (var i = 0u; i < 16; ++i) { if (off + i >= len) { break; } var c = (char)data[off + i]; if (data[off + i] < 0x80 && (char.IsLetterOrDigit(c) || !char.IsControl(c) || char.IsSymbol(c) || c == ' ')) { printable += c; } else { printable += '.'; } } // const int BP_OFFSET = 9, BP_GRAPH = 60, BP_LEN = 80; RTMP_Log(level, " {0:x4}: {1, -24} {2, -24} {3, -18}", off, dump1, dump2, printable); } }
/// <summary> void RTMP_Log(int level, const char *format, ...) </summary> public static void RTMP_Log(RTMP_LogLevel level, string fmt, params object[] vals) { cb(level, fmt, vals); }
/// <summary> void RTMP_LogSetLevel(RTMP_LogLevel level) </summary> public static void RTMP_LogSetLevel(RTMP_LogLevel level) { RTMP_debuglevel = level; }