} // CLogFilter /// <summary> /// Check if a message of the given level would actually be logged /// </summary> /// <param name="record">a message logging level</param> /// <returns>true if the given message level is currently being logged.</returns> bool Filter.IsLoggable(LogRecord record) { if (record.GetLevel() == Level.SEVERE || record.GetLevel() == Level.WARNING) { return(true); } // String loggerName = record.GetLoggerName(); if (loggerName != null) { // if (loggerName.toLowerCase().indexOf("focus") != -1) // return true; if (loggerName.StartsWith("System.")) { return(false); } } String className = record.sourceClassName; if (className != null) { if (className.StartsWith("System.")) { return(false); } } return(true); } // isLoggable
public override void Publish(LogRecord record) { if (DateTime.Now.Date != _lastFileDate) //Set Now Date { Initialize(_viennaHome, true, true); } if (!IsLoggable(record) || _writer == null) { return; } // Format String msg = null; try { msg = GetFormatter().Format(record); } catch { return; } try { if (!_doneHeader) { _writer.WriteLine(GetFormatter().GetHead()); //AllocConsole(); //Console.WriteLine(GetFormatter().GetHead()); // outputs to console window _doneHeader = true; } _writer.WriteLine(msg); //AllocConsole(); //Console.WriteLine(msg); // outputs to console window m_records++; //if (string.IsNullOrEmpty(record.message)) // record.message = "Executed"; if (record.GetLevel() == Level.SEVERE || record.GetLevel() == Level.WARNING || m_records % 10 == 0) // flush every 10 records { Flush(); } //print into file //_writer.WriteLine(this.Format(record)); //_writer.Flush(); //finally flush the print } catch { Close(); _lastFileDate = null; //try next time when publish is called //try again to initlize file } }
public void Log(LogRecord record) { if (record.GetLevel().IntValue() < levelValue || levelValue == offValue) { return; } //lock (this) // { if (filter != null && !filter.IsLoggable(record)) { return; } //} // Post the LogRecord to all our Handlers, and then to // our parents' handlers, all the way up the tree. Logger logger = this; while (logger != null) { Handler[] targets = logger.GetHandlers(); if (targets != null) { for (int i = 0; i < targets.Length; i++) { //VLogFile.Publish (abstract method) targets[i].Publish(record); } } logger = logger.GetParent(); } }
/// <summary> /// Get Log Data /// </summary> /// <param name="errorsOnly">if true errors otherwise log</param> /// <returns> data array</returns> public object[,] GetLogData(bool errorsOnly) { LogRecord[] records = GetRecords(errorsOnly); // System.out.println("getLogData - " + events.length); //List<List<Object>> rows = new List<List<Object>>(records.Length); errorData = new object[records.Length, 4]; for (int i = 0; i < records.Length; i++) { LogRecord record = records[i]; List <Object> cols = new List <Object>(); // string time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ms"); time = time + "00"; time = time.Substring(11, 23 - 11); errorData[i, 0] = time; errorData[i, 1] = record.GetLevel().GetName(); errorData[i, 2] = VLogFormatter.GetClassMethod(record); errorData[i, 3] = record.message; //cols.Add(DateTime.Now.ToString()); //cols.Add(record.GetLevel().GetName()); // //cols.Add(VLogFormatter.GetClassMethod(record)); //cols.Add(record.message); // //cols.Add(CLogFormatter.getParameters(record)); //cols.Add(CLogFormatter.getExceptionTrace(record)); // //rows.Add(cols); } return(errorData); } // getData
/// <summary> /// Check if this <tt>Handler</tt> would actually log a given <tt>LogRecord</tt>. /// <para> /// This method checks if the <tt>LogRecord</tt> has an appropriate /// <tt>Level</tt> and whether it satisfies any <tt>Filter</tt>. It also /// may make other <tt>Handler</tt> specific checks that might prevent a /// handler from logging the <tt>LogRecord</tt>. It will return false if /// the <tt>LogRecord</tt> is Null. /// </para> /// </summary> /// <param name="record">LogRecord</param> /// <returns>true, if the LogRecord would be logged</returns> public bool IsLoggable(LogRecord record) { int levelValue = GetLevel().IntValue(); if (record.GetLevel().IntValue() < levelValue || levelValue == offValue) { return(false); } Filter filter = GetFilter(); if (filter == null) { return(true); } return(filter.IsLoggable(record)); }
/// <summary> /// Format /// </summary> /// <param name="record">LogRecord</param> /// <returns>formatted string</returns> public override String Format(LogRecord record) { StringBuilder sb = new StringBuilder(); //time of execution string time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ms"); time = time + "00"; /** Time/Error */ if (record.GetLevel() == Level.SEVERE) { // 12.12.12.123 sb.Append("===========> "); sb.Append(" (SEVERE) "); //if (VAdvantage.DataBase.Ini.IsClient()) // System.Media.SystemSounds.Beep.Play(); } else if (record.GetLevel() == Level.WARNING) { // 12.12.12.123 sb.Append("-----------> "); sb.Append(" (WARNING) "); } else { //123456789123456789 sb.Append(time.Substring(11, 23 - 11)); //int spaces = 11; if (record.GetLevel() == Level.INFO) { sb.Append(" (INFO) "); } else if (record.GetLevel() == Level.CONFIG) { sb.Append(" (CONFIG) "); } else if (record.GetLevel() == Level.FINE) { sb.Append(" (FINE) "); } else if (record.GetLevel() == Level.FINER) { sb.Append(" (FINER) "); } else if (record.GetLevel() == Level.FINEST) { sb.Append(" (FINEST) "); } //sb.Append(" ".Substring(0, spaces)); } /** Class.method **/ if (!_shortFormat) { sb.Append(GetClassMethod(record)).Append(": "); } /** Message **/ sb.Append(record.message); //sb.Append(record.sourceClassName + "." + record.sourceMethodName + " > " + record.lineNumber + " > " + record.message); return(sb.ToString()); }
} // SetLevel /// <summary> /// Publish /// Logging.Handler#Publish() /// </summary> /// <param name="record"></param> public override void Publish(LogRecord record) { if (!IsLoggable(record) || m_logs == null) { return; } // Output lock (m_logs) { if (m_logs.Count >= LOG_SIZE) { m_logs.RemoveFirst(); } m_logs.AddLast(record); } // We have an error if (record.GetLevel() == Level.SEVERE) { if (m_errors.Count >= ERROR_SIZE) { m_errors.RemoveFirst(); m_history.RemoveFirst(); } // Add Error m_errors.AddLast(record); //record.sourceClassName; // forces Class Name eval // Create History List <LogRecord> history = new List <LogRecord>(); try { foreach (LogRecord logr in m_logs) { LogRecord rec = (LogRecord)logr; if (rec.GetLevel() == Level.SEVERE) { if (history.Count == 0) { history.Add(rec); } else { break; // don't incluse previous error } } else { history.Add(rec); if (history.Count > 10) { break; // no more then 10 history records } } } } catch { } LogRecord[] historyArray = new LogRecord[history.Count]; int no = 0; for (int i = history.Count - 1; i >= 0; i--) { historyArray[no++] = (LogRecord)history[i]; } m_history.AddLast(historyArray); // Issue Reporting if (m_issueError) { String loggerName = record.GetLoggerName(); // class name // String className = record.getSourceClassName(); // physical class String methodName = record.sourceMethodName; // if (!methodName.Equals("SaveError") && !methodName.Equals("Get_Value") && !methodName.Equals("DataSave") && loggerName.IndexOf("Issue") == -1 && loggerName.IndexOf("CConnection") == -1 // && VAdvantage.DataBase.DB.IsConnected() ) { m_issueError = false; //MIssue.create(record); m_issueError = true; } } } }