示例#1
0
文件: Log.cs 项目: ngzero/madb
 /// <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 ( logLevel.Priority >= Level.Priority ) {
         if ( LogOutput != null ) {
             LogOutput.Write ( logLevel, tag, message );
         } else {
             Write ( logLevel, tag, message );
         }
     }
 }
示例#2
0
文件: Log.cs 项目: ngzero/madb
        /// <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;
            }
        }
示例#3
0
文件: Log.cs 项目: ngzero/madb
 /// <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 );
     }
 }
示例#4
0
文件: Log.cs 项目: ngzero/madb
 /// <summary>
 /// Prints a log message.
 /// </summary>
 /// <param name="logLevel"></param>
 /// <param name="tag"></param>
 /// <param name="message"></param>
 public static void Write( LogLevel.LogLevelInfo logLevel, String tag, String message )
 {
     Console.Write ( GetLogFormatString ( logLevel, tag, message ) );
 }
示例#5
0
文件: Log.cs 项目: ngzero/madb
 /// <summary>
 /// Formats a log message.
 /// </summary>
 /// <param name="logLevel"></param>
 /// <param name="tag"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static String GetLogFormatString( LogLevel.LogLevelInfo logLevel, String tag, String message )
 {
     long msec = DateTime.Now.ToUnixEpoch ( );
     return String.Format ( "{0:00}:{1:00} {2}/{3}: {4}\n", ( msec / 60000 ) % 60, ( msec / 1000 ) % 60,
                     logLevel.Letter, tag, message );
 }