← Back to team overview

sikuli-driver team mailing list archive

[Bug 1350735] Re: [request] want options to redirect Sikuli's log messages to my own logging

 

-- the gem:
now only available on rubygems.org the version 1.1.0.2 should work.
https://rubygems.org/gems/sikulix

-- the logger redirect:
only to be clear:
$log must contain a logger instance, that contains as instance methods with the subsequently issued names.
the methods MUST have only one possible string parameter.

this was my functional test in Java, that worked.

public class APITest {

	@Test
	public void addingPrivateLogger() {
		Debug.test("addingPrivateLogger");
		Debug.info("this should be visible as info message");
		Debug.action("this should be visible as action log message");
		Debug.log("this should be visible as debug message");
		Debug.error("this should be visible as error message");
		boolean success = true;
		Debug.setLogger(new APITest());
		success &= Debug.setLoggerAll("info");
		Assert.assertTrue(success);
	}

	@Test
	public void usingPrivateLoggerInfo() {
		Debug.test("usingPrivateLogger");
		Debug.info("test message info");
		Debug.action("test message action log");
		Debug.error("test message error");
		Assert.assertTrue(true);
	}

	public void info(String msg) {
		System.out.println("[TEST] myLogger.info: " + msg);
	}
}

Might be, that you have to cast the given method name string to a java
language string.

I think as a first step, you should make sure, that it works on the java
level in your environment and then step up to JRuby.

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1350735

Title:
  [request] want options to redirect Sikuli's log messages to my own
  logging

Status in Sikuli:
  In Progress

Bug description:
  A previous thread that is closest to answering my current question is:
      https://answers.launchpad.net/sikuli/+question/248604
  in which RaiMan suggest the usage of a setSikuliXLogCallback

  I searched the net for setSikuliXLogCallback, but the only hit I got
  was that thread.  Hence this question/plea for more detail.

  I recently started looking into Sikuli using IDE first, then I moved onto using standalone Jython, and then finally had the courage to venture into using Ruby, which is the primary language of my test framework.
  I was pleasantly surprised how easy and great the interface was. Kudos to RaiMan and contributors on this great tool.

  Now, onto my question...
  I can redirect the java output to a single log file via Debug.setLogFile(log_file). 
  My test framework, however, uses Log4R which direct the log output to multiple files as well as the console. 
  Ideally I would like to redirect the logging requests to my logger to do it's thing, so that I can get all the output like:
  [LOG] CLICK on L(27,10)@S(0)[0,0 1440x900]
  in the standard log files.

  I kind-a implemented a workaround that does this as follows:
  1. I put in a one-line callback patch in the native_exception_protect() method  in the sikulix.rb  file, like this:
              m.bind(self).call(*args)  # previous existing line
              SikuliX4Ruby.post_region_callback(m) if SikuliX4Ruby.respond_to?(:post_region_callback)  # line added

  2.  Redirected the java logs to a temp file first, by defining and calling the following:
  module SikuliLib
     def self.log_file=(log_file)
      @@log_file = log_file
      Debug.setLogFile(log_file)
  end

  3.  Captured the original logoutput and logged it via myLogger as such:
  module SikuliX4Ruby
    def self.post_region_callback(method = nil, obj =nil)
      file = SikuliLib.log_file
      File.readlines(file).each { |line| myLogger.info(line.chomp) } if File.size?(file)
      FileUtils.rm file
    end
  end

  My workaround does the trick for now, but I'm not happy about the fact that I had to copy and patch the sikulix.rb file.
  I would rather not muck with original SikuliX distribution files and use a callback that is officially supported, if there is one (The previous question thread hinted that there might be one already.)

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1350735/+subscriptions


References