Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

How can I redirect loggers output to the JForex console ?
 Post subject: How can I redirect loggers output to the JForex console ? Post rating: 0   New post Posted: Sun 30 Jan, 2011, 11:58 

User rating: 0
Joined: Sun 30 Jan, 2011, 11:43
Posts: 6
Good day,

I tried migrate my indicators/strategies to use log4j or slf4j, but I see none of the output in the JForex console, while there is an output when I run the same code from the command line.
How can I redirect loggers output to the JForex console ?
Many thanks.

/*
** THIS IS TYPICALLY WHAT I DO WITH Log4J
*/
import java.lang.*;
import org.apache.log4j.*;

public class TestLog4J {
       private static final Logger logger = Logger.getLogger(TestLog4J.class);

       public static void main(String[] args) {
               System.out.println("Hello log4j");

               BasicConfigurator.configure();
               logger.setLevel(Level.ALL);
               logger.info("logger started");
               }
       }

======
/*
** THIS IS TYPICALLY WHAT I DO WITH slf4j
*/
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

public class TestSlf4j {
       private static final Logger logger = LoggerFactory.getLogger ( TestSlf4j.class ); // slf4j
       private static org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();

       public static void main(String[] args) {
               System.out.println("Hello slf4j");

               org.apache.log4j.BasicConfigurator.configure();
               root.setLevel(org.apache.log4j.Level.ALL);
               logger.info("logging configured");
               }               }


 
 Post subject: Re: How can I redirect loggers output to the JForex console Post rating: 0   New post Posted: Wed 15 Jun, 2011, 11:16 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider the following startegy for testing slf4j logging to the JForex client java console:
package jforex.logging;

import com.dukascopy.api.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RequiresFullAccess
@Library("C:/temp/log4j-over-slf4j-1.6.1.jar;C:/temp/slf4j-api-1.6.1.jar")
public class LoggingTests implements IStrategy {

   public void onStart(IContext context) throws JFException {
      Logger logger = LoggerFactory.getLogger(LoggingTests.class);
      logger.info("log test");

   }
   public void onTick(Instrument instrument, ITick tick) throws JFException {}
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onAccount(IAccount account) throws JFException {}
   public void onStop() throws JFException {}
}
Make sure to have the appropriate jars in your file system and to have them referenced from the strategy.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com