コード例 #1
0
ファイル: LogActivity.cs プロジェクト: orf53975/openvpn-Eddie
        private List <string> GetCurrentLog(FormatType formatType = FormatType.HTML, LogTime logTime = LogTime.UTC)
        {
            SimpleDateFormat dateFormatter = null;
            Date             logCurrenTimeZone = null;
            Calendar         calendar = null;
            List <string>    logItem = null;
            List <LogItem>   eddieLog = null;
            long             utcTimeStamp = 0;
            string           log = "", logColor = "", levelDescription = "";

            calendar = Calendar.Instance;

            dateFormatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");

            if (logTime == LogTime.UTC)
            {
                dateFormatter.TimeZone = Java.Util.TimeZone.GetTimeZone("GMT");
            }
            else
            {
                dateFormatter.TimeZone = Java.Util.TimeZone.Default;
            }

            eddieLog = EddieLogger.GetLog();

            if (eddieLog == null)
            {
                return(null);
            }

            logItem = new List <string>();

            foreach (LogItem item in eddieLog)
            {
                utcTimeStamp = item.utcUnixTimestamp;

                calendar.TimeInMillis = utcTimeStamp * 1000;
                logCurrenTimeZone     = (Date)calendar.Time;

                if (item.logLevel == Level.Severe)
                {
                    logColor         = "red";
                    levelDescription = "Error";
                }
                else if (item.logLevel == Level.Info)
                {
                    logColor         = "darkgreen";
                    levelDescription = "Info";
                }
                else if (item.logLevel == Level.Warning)
                {
                    logColor         = "orange";
                    levelDescription = "Warning";
                }
                else if (item.logLevel == Level.Fine)
                {
                    logColor         = "purple";
                    levelDescription = "Debug";
                }
                else
                {
                    logColor         = "black";
                    levelDescription = item.logLevel.ToString();
                }

                switch (formatType)
                {
                case FormatType.HTML:
                {
                    log  = "<font color='blue'>" + dateFormatter.Format(logCurrenTimeZone) + "</font>";
                    log += " [<font color='" + logColor + "'>" + levelDescription + "</font>]: ";
                    log += item.message.Replace("\n", "<br>");
                }
                break;

                case FormatType.PLAIN_TEXT:
                {
                    log = dateFormatter.Format(logCurrenTimeZone) + " UTC [" + levelDescription + "] " + item.message;
                }
                break;

                default:
                {
                    log = "";
                }
                break;
                }

                logItem.Add(log);
            }

            return(logItem);
        }