Example #1
0
        /// <summary>
        /// prints to stdout; could write to a log window
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="tag"></param>
        /// <param name="message"></param>
        private static void WriteLine(LogLevel.LogLevelInfo logLevel, string tag, string message)
        {
            if (ThresholdLevel.Priority <= logLevel.Priority)
                {
                if (LogOutput != null)
                    LogOutput.Write(logLevel, tag, message);
                else
                    WriteUnchecked(logLevel, tag, message);

                WriteDebugUnchecked(logLevel, tag, message);
                }
        }
Example #2
0
        /// <summary>
        /// Dump the entire contents of a byte array with DEBUG priority.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="level"></param>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <remarks>
        /// Local addition.  Output looks like:
        /// 1230- 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff  0123456789abcdef
        /// Uses no string concatenation; creates one String object per line.
        /// </remarks>
        internal static void HexDump(string tag, LogLevel.LogLevelInfo level, byte[] data, int offset, int length )
        {
            int kHexOffset = 6;
            int kAscOffset = 55;
            char[] line = new char[SpaceLine.Length];
            int addr, baseAddr, count;
            int i, ch;
            bool needErase = true;

            //Log.w(tag, "HEX DUMP: off=" + offset + ", length=" + length);

            baseAddr = 0;
            while ( length != 0 ) {
                if ( length > 16 ) {
                    // full line
                    count = 16;
                } else {
                    // partial line; re-copy blanks to clear end
                    count = length;
                    needErase = true;
                }

                if ( needErase ) {
                    Array.Copy ( SpaceLine, 0, line, 0, SpaceLine.Length );
                    needErase = false;
                }

                // output the address (currently limited to 4 hex digits)
                addr = baseAddr;
                addr &= 0xffff;
                ch = 3;
                while ( addr != 0 ) {
                    line[ch] = HEXDIGIT[addr & 0x0f];
                    ch--;
                    addr >>= 4;
                }

                // output hex digits and ASCII chars
                ch = kHexOffset;
                for ( i = 0; i < count; i++ ) {
                    byte val = data[offset + i];

                    line[ch++] = HEXDIGIT[( val >> 4 ) & 0x0f];
                    line[ch++] = HEXDIGIT[val & 0x0f];
                    ch++;

                    if ( val >= 0x20 && val < 0x7f )
                        line[kAscOffset + i] = (char)val;
                    else
                        line[kAscOffset + i] = '.';
                }

                WriteLine ( level, tag, new string( line ) );

                // advance to next chunk of data
                length -= count;
                offset += count;
                baseAddr += count;
            }
        }
Example #3
0
 public static void WriteUnchecked(LogLevel.LogLevelInfo logLevel, string tag, string message)
 {
     Console.WriteLine(GetLogFormatString(logLevel, tag, message));
 }
Example #4
0
 public static void WriteDebugUnchecked(LogLevel.LogLevelInfo logLevel, string tag, string message)
 {
     System.Diagnostics.Trace.Write($"{Util.TraceTag}| {GetLogFormatString(logLevel, tag, message)}");
 }
Example #5
0
 /// <summary>
 /// Outputs a log message and attempts to display it in a dialog.
 /// </summary>
 /// <param name="logLevel">The log level</param>
 /// <param name="tag">The tag associated with the message.</param>
 /// <param name="message">The message to output.</param>
 public static void LogAndDisplay( LogLevel.LogLevelInfo logLevel, string tag, string message )
 {
     if ( LogOutput != null ) {
         LogOutput.WriteAndPromptLog ( logLevel, tag, message );
     } else {
         WriteLine ( logLevel, tag, message );
     }
 }
Example #6
0
 public static string GetLogFormatString(LogLevel.LogLevelInfo logLevel, string tag, string message)
 {
     long msec = DateTime.Now.ToUnixEpoch();
     return $"{(msec/60000)%60:00}:{(msec/1000)%60:00} {logLevel.Letter}/{tag}: {message}";
 }