001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.util; 020 021/** 022 * LogSources can choose to extends this SimpleLogSource 023 * 024 * @author apr@cs.com.uy 025 * @version $Id$ 026 * @see LogSource 027 */ 028public class SimpleLogSource implements LogSource { 029 /** The logger used by this log source. */ 030 protected Logger logger; 031 /** The logging realm for this log source. */ 032 protected String realm; 033 034 /** Default constructor. */ 035 public SimpleLogSource () { 036 super(); 037 logger = null; 038 realm = null; 039 } 040 /** 041 * Constructs a SimpleLogSource with the given logger and realm. 042 * @param logger the logger to use 043 * @param realm the logging realm 044 */ 045 public SimpleLogSource (Logger logger, String realm) { 046 setLogger (logger, realm); 047 } 048 /** 049 * Sets the logger and realm for this log source. 050 * @param logger the logger to use 051 * @param realm the logging realm 052 */ 053 public void setLogger (Logger logger, String realm) { 054 this.logger = logger; 055 this.realm = realm; 056 } 057 /** 058 * Returns the logging realm. 059 * @return the realm string 060 */ 061 public String getRealm () { 062 return realm; 063 } 064 /** 065 * Returns the logger. 066 * @return the logger 067 */ 068 public Logger getLogger() { 069 return logger; 070 } 071 /** 072 * Sets the logging realm. 073 * @param realm the realm string 074 */ 075 public void setRealm (String realm) { 076 this.realm = realm; 077 } 078 /** 079 * Logs an informational message. 080 * @param detail the message text 081 */ 082 public void info (String detail) { 083 Logger.log (new LogEvent (this, "info", detail)); 084 } 085 /** 086 * Logs an informational message with an attached object. 087 * @param detail the message text 088 * @param obj the object to attach 089 */ 090 public void info (String detail, Object obj) { 091 LogEvent evt = new LogEvent (this, "info", detail); 092 evt.addMessage (obj); 093 Logger.log (evt); 094 } 095 /** 096 * Logs a warning message. 097 * @param detail the warning text 098 */ 099 public void warning (String detail) { 100 Logger.log (new LogEvent (this, "warning", detail)); 101 } 102 /** 103 * Logs a warning message with an attached object. 104 * @param detail the warning text 105 * @param obj the object to attach 106 */ 107 public void warning (String detail, Object obj) { 108 LogEvent evt = new LogEvent (this, "warning", detail); 109 evt.addMessage (obj); 110 Logger.log (evt); 111 } 112 /** 113 * Logs an error message. 114 * @param detail the error text 115 */ 116 public void error (String detail) { 117 Logger.log (new LogEvent (this, "error", detail)); 118 } 119 /** 120 * Logs an error message with an attached object. 121 * @param detail the error text 122 * @param obj the object to attach 123 */ 124 public void error (String detail, Object obj) { 125 LogEvent evt = new LogEvent (this, "error", detail); 126 evt.addMessage (obj); 127 Logger.log (evt); 128 } 129} 130