forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1304 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
b16182c3a8
commit
bc655a7a89
@ -1,136 +0,0 @@
|
||||
/*
|
||||
* SIPRPLogger.java
|
||||
*
|
||||
* Created on 15 de Marco de 2005, 15:31
|
||||
*/
|
||||
|
||||
package siprp;
|
||||
|
||||
import com.evolute.project.ProjectTools;
|
||||
import com.evolute.utils.Singleton;
|
||||
import com.evolute.utils.db.DBManager;
|
||||
import com.evolute.utils.db.Executer;
|
||||
import com.evolute.utils.db.SQLRetriever;
|
||||
import com.evolute.utils.error.Logger;
|
||||
import com.evolute.utils.sql.Assignment;
|
||||
import com.evolute.utils.sql.Field;
|
||||
import com.evolute.utils.sql.Insert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lflores
|
||||
|
||||
* MySQL
|
||||
CREATE TABLE errors
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
PRIMARY KEY( id ),
|
||||
date TIMESTAMP NOT NULL DEFAULT 'now()',
|
||||
type VARCHAR(20),
|
||||
environment VARCHAR( 255 ),
|
||||
description TEXT
|
||||
);
|
||||
*
|
||||
*PostgreSQL
|
||||
CREATE TABLE errors
|
||||
(
|
||||
id SERIAL,
|
||||
PRIMARY KEY( id ),
|
||||
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
type VARCHAR(20),
|
||||
environment VARCHAR( 255 ),
|
||||
description VARCHAR( 256000 )
|
||||
)
|
||||
|
||||
*/
|
||||
public class SHSTLogger implements Logger
|
||||
{
|
||||
private final String java = System.getProperty( "java.version" )
|
||||
+ "-" + System.getProperty( "java.vm.version" );
|
||||
private final String os = System.getProperty( "os.name" ) + " - " +
|
||||
System.getProperty( "os.version" );
|
||||
private final String user = ( String )Singleton.getInstance( Singleton.USERNAME );
|
||||
private final String ENV = "Java: " + java + " \nOS: " + os + " \nUser: " + user
|
||||
+ "\n Software: " + ( String )Singleton.getInstance( SingletonConstants.SOFTWARE_NAME )
|
||||
+ "\n Version: " + ProjectTools.getInstance().getVersion();
|
||||
private final Executer executer;
|
||||
|
||||
/** Creates a new instance of SIPRPLogger */
|
||||
public SHSTLogger()
|
||||
throws Exception
|
||||
{
|
||||
DBManager dbm = ( DBManager )Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
|
||||
executer = dbm.getExclusiveExecuter( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log( String str )
|
||||
{
|
||||
String mem = "(" + Runtime.getRuntime().freeMemory() + "/" +
|
||||
Runtime.getRuntime().maxMemory() + ")";
|
||||
if( str.length() > 254000 )
|
||||
{
|
||||
str = str.substring( 0, 254000 ) + " Message too big (" + str.length() + "), truncated.";
|
||||
}
|
||||
try
|
||||
{
|
||||
executer.executeQuery( new Insert( "errors", new Assignment[] {
|
||||
new Assignment( new Field( "type" ), "LOG" ),
|
||||
new Assignment( new Field( "environment" ), ENV + mem ),
|
||||
new Assignment( new Field( "description" ), str )
|
||||
} ), null );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
logException( ex );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logException( Throwable ex )
|
||||
{
|
||||
StackTraceElement ste[] = ex.getStackTrace();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for( int i = 0; i < ste.length; ++i )
|
||||
{
|
||||
sb.append( ste[ i ].toString() );
|
||||
}
|
||||
String str = "Exception Message: " + ex.getMessage() + "\nStack Trace: " + sb.toString();
|
||||
String mem = "(" + Runtime.getRuntime().freeMemory() + "/" +
|
||||
Runtime.getRuntime().maxMemory() + ")";
|
||||
if( str.length() > 254000 )
|
||||
{
|
||||
str = str.substring( 0, 254000 ) + " Message too big (" + str.length() + "), truncated.";
|
||||
}
|
||||
try
|
||||
{
|
||||
executer.executeQuery( new Insert( "errors", new Assignment[] {
|
||||
new Assignment( new Field( "type" ), "ERROR" ),
|
||||
new Assignment( new Field( "environment" ), ENV + mem ),
|
||||
new Assignment( new Field( "description" ), str )
|
||||
} ), new SQLRetriever() );
|
||||
}
|
||||
catch( Exception ex1 )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String str, java.util.logging.Level level) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logException(Throwable ex, java.util.logging.Level level) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package siprp;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.evolute.project.ProjectTools;
|
||||
import com.evolute.utils.error.ErrorLogger;
|
||||
import com.evolute.utils.error.LoggerProperties;
|
||||
import com.evolute.utils.error.ProjectsEnum;
|
||||
import com.evolute.utils.error.ws.WSLogger;
|
||||
import com.evolute.utils.network.proxy.EvoProxyObject;
|
||||
|
||||
public class SIPRPLoggerInit
|
||||
{
|
||||
|
||||
static void init()
|
||||
{
|
||||
Map<LoggerProperties, String> map = new HashMap<LoggerProperties, String>();
|
||||
|
||||
map.put( LoggerProperties.PROJECT, ProjectsEnum.SIPRP.toString() );
|
||||
map.put( LoggerProperties.SOFTWARE_VERSION, ProjectTools.getInstance().getVersion().toString() );
|
||||
map.put( LoggerProperties.SOFTWARE_NAME, "SIPRPSoft" );
|
||||
|
||||
try
|
||||
{
|
||||
EvoProxyObject.configSystemProxySelector();
|
||||
EvoProxyObject.getProxy();
|
||||
ErrorLogger.initializeLogger( new WSLogger( map ) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
ErrorLogger.logException( e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue