[1.0.1] How to save sikuli logs into an external file
Hi,
I am using Sikuli+TestNG+Maven with java and I run the tests as a testng suite from command line using maven command 'mvn test'.
When run tests, i see logs generated by sikuli like -
Click (280, 350), exists(280, 350) etc....
Now, I wanted to save all these logs into an external file automatically after test run, in logs.log file or .txt file.
Can someone help me in implementing this.
Thanks & Regards
Deepa
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Revision history for this message
![]() |
#1 |
--1. log verbosity
there are switches, that control the log verbosity of Sikuli:
Settings.
Settings.
setting to false: the respective logs will be suppressed
additionally there are [error] messages in some situations, which cannot be suppressed currently.
--2. user logs (version 1.0.1+)
you can have user logs (starting with label [user] in the standard)
Settings.
Settings.
usage: see the method org.sikuli.
--3. with timestamp (version 1.0.1+)
Sikuli logs and user logs can have time stamps at the end of the label
Settings.LogTime = true/false; // switch on/off for Sikuli logs
Settings.
--4. write the logs to a file (version 1.0.1+)
the class org.sikuli.
setLogFile(String fileName); // opens a PrintStream for the given file, where all Sikuli logs are written
setUserLogFile(
both can be called with filename as null. Then the filename is expected in java system properties
sikuli.Logfile and sikuli.LogfileUser respectively.
Revision history for this message
![]() |
#2 |
Thanks RaiMan for the reply.
For now, i have manually placed a blank txt file log.txt under project directory/logs folder &
I have downloaded and added sikuli-setup.jar to my project classpath (in order to use org.sikuli.basics) and added above mentioned steps 1 and 4 into my test script. My test script now, look like below:
package dataEntry;
import java.io.
import org.sikuli.
import org.sikuli.
import org.sikuli.
import static org.sikuli.
import static org.testng.
public class OE_SP1_AFDataEntry {
@Test
public void TestDataEntry() throws FindFailed, IOException,
InterruptedE
try
{
String path_or = System.
Screen screen = new Screen();
Settings.
Settings.
screen.
assertTrue(
screen.
assertTrue(
screen.
assertTrue(
}
catch(Exception e)
{
assertTrue(
}
setLogFile(
}
}
This script is executed successfully but the log.txt file is still blank. No logs have been copied to log.txt file.
Please let me know if I am doing any mistake here.
Thanks & Regards
Deepa
Revision history for this message
![]() |
#3 |
--1: sikuli-setup.jar in classpath ...
... not needed (and not recommended), since the package org.sikuli.basics is already contained in each of the ready-to-use jars sikuli-ide.jar, sikuli-script.jar and sikuli-java.jar
--2: catching the click log entries
package dataEntry;
import java.io.
import org.sikuli.
import org.sikuli.
import org.sikuli.
import static org.sikuli.
import static org.testng.
public class OE_SP1_AFDataEntry {
static {
Debug.
}
@Test
public void TestDataEntry() throws FindFailed, IOException,
InterruptedE
try
{
String path_or = System.
Screen screen = new Screen();
Settings.
screen.
assertTrue(
screen.
assertTrue(
screen.
assertTrue(
}
catch(Exception e)
{
assertTrue(
}
}
}
Revision history for this message
![]() |
#4 |
I just realised, that you are using RC3 (and not 1.0.1), since
import org.sikuli.
only works with RC3
The Settings class has been moved to org.sikuli.basics in version 1.0+
With RC3 there is no option, to write the Sikuli logs to a file. To get this option (see comment #1) you have to switch completely to version 1.0.1 (RC3 and 1.0.1 cannot be mixed).
Revision history for this message
![]() |
#5 |
Thanks RaiMan,
I am trying to updated my sikuli version to 1.0.1, but facing some configuration issues. Below are the steps i followed:
1. Deleted existing old version of sikuliX folder from c:/program files
2. Created a new folder - c:/SikuliX
3. Downloaded sikuli-setup.jar in this folder
4. double clicked this jar and followed instructions in wizard
5. Now i got - libs/ , runScript.cmd, runSetup.cmd, sikuli-java.jar, sikuli-script.jar, SikuiX-
6. I copied sikuli-java.jar and sikuli-script.jar to my projects lib folder - c:/projects/
7. Added these jars to my project's classpath (c:/projects/
8. modified sikuli path in my environment system variables - SIKULI-HOME and PATH from c:/programfiles
9. Now i added above :
static {
Debug.
}
to my script
10. When i run the script from eclipe, logs were generated in log.txt but its showing configuration error:
[error] ResourceLoaderB
[action] ResourceLoaderB
[info] runcmd: reg QUERY HKCU
[info] runcmd: reg QUERY HKEY_CURRENT_
[info] runcmd: reg ADD HKEY_CURRENT_
[info] runcmd: reg QUERY HKEY_CURRENT_
[error] ResourceLoaderB
RESTART all processes/IDE's using Sikuli for new PATH to be used!/nFor usages from command line logout/login might be necessary!
[error] Terminating SikuliX after a fatal error! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.
11. I also observe, the path - "C:\projects\
Please advice to resolve this issue
Thanks & Regards
Deepa
Revision history for this message
![]() |
#6 |
Steps 1 to 5 are ok.
Sikuli version 1.0.1 has these enhancements against RC3:
- the libs folder is automatically created from the active sikuli jar (sikuli-java.jar in your case) in the folder containing the jar
- on Windows the path to this libs folder is automatically added to the system path via registry (therefor you should do what is stated: logout/login might be necessary! (this is clearer in 1.1))
So it is strongly recommended, to not move around the Sikuli stuff, but leave it in the setup folder and use references instead.
(So steps 6, 7 and 8 should not happen).
Neither a manual entry to the system path nor SIKULI_HOME is needed (which is BTW SIKULIX_HOME for 1.0.1+, but not needed as well ;-)
You have to add c:\SikuliX\
Revision history for this message
![]() |
#7 |
Thanks RaiMan, that solved my question.
Revision history for this message
![]() |
#8 |
Thanks Raiman, Though my problem has been resolved, I still have few questions :
1. As I am using Maven, are these sikuli-java and sikuli-script 1.0.1 jars are part of maven central repository to use as dependency in my POM ?
As my project need to refer these jars from my local sikuli's installation folder (C:/SikuliX), is it possible to use maven repository ?
Currently i am defining dependency in POM as:
<dependency>
<groupId>
<artifactId>
<version>
<systemPath>
<scope>
</dependency>
The reason i am asking this is - If I share my maven project to some of my colleague , he need to have sikuli installed in his local machine to run my project ? OR any dependency defined in POM can handle this ?
2. Can you also please give me an example code to add my own defined logs to the log.txt file. I also wanted to add few lines of text in log.txt file after each step of test execution
Revision history for this message
![]() |
#9 |
--- Maven Central
... SikuliX is not yet there. I will have it there after I am ready with version 1.1.0 early in 2014.
until then you either have to install it into your local repo or use a dependency declaration like yours.
BTW: since you are using Maven, I suppose you develop in plain Java. if this is true, then you do not need sikuli-script.jar. This is simply sikuli-java.jar + Jython script run support with a bundled Jython package. So if you only use Java or even Jython scripting with your own Jython installation (or IDE support) sikuli-java.jar is the only thing you need.
--- Sikuli Java apps on other machines
... if you only want to run your app on another machine with the same system (Windows in your case), you do not need any "installation".
The only thing needed is the sikuli-java.jar, that you already used.
You even might make a fat jar (Maven assembly plugin), that completely contains sikuli-java.jar.
The most ugly thing with Sikuli on Windows is the fact, that you need a ref to Sikuli's libs folder in the system path at runtime.
If it is possible, to use a command file, to start your app, then the easiest solution is to wrap the java execution into setlocal/endlocal with a PATH=<path-
At runtime Sikuli first checks the existence of the libs folder. If none exists or the existing one is invalid, the libs folder usually is created in the folder, where the jar is and filled with the libs by export from the jar.
On Windows additionally it is checked, wether a ref to this libs folder is in the system path. If it is not, then Sikuli adds it via registry. But you have to restart the app or even your session (logout/ login).
BTW: on Windows, the same sikuli-java.jar works with Java 32-Bit and Java 64-Bit: at runtime simply the library set is changed dynamically via export from jar.
Revision history for this message
![]() |
#10 |
your question 2 from comment #8: I simply do not understand what you want to see.
Revision history for this message
![]() |
#11 |
Thanks RaiMan, My question 2 from comment #8 is about the user logs:
Currently, Sikuli's default logs are getting saved in log.txt and these logs look like below :
[log] CLICK on L(1064, 538)@S(0) [0,0 1920X1080]
[log] TYPE "username"
[log] CLICK on L(1064, 571)@S(0) [0,0 1920X1080]
[log] TYPE "password"
[log] CLICK on L(1074, 627)@S(0) [0,0 1920X1080]
[log] CLICK on L(93, 198)@S(0) [0,0 1920X1080]
[log] CLICK on L(1906, 991)@S(0) [0,0 1920X1080]
In addition to these logs, i want to insert my own log messages into this log.txt file which I want the log to look like :
[MyLog] Logging in to the application
[log] CLICK on L(1064, 538)@S(0) [0,0 1920X1080]
[log] TYPE "username"
[log] CLICK on L(1064, 571)@S(0) [0,0 1920X1080]
[log] TYPE "password"
[log] CLICK on L(1074, 627)@S(0) [0,0 1920X1080]
[MyLog] Clicking on Data Menu
[log] CLICK on L(93, 198)@S(0) [0,0 1920X1080]
[MyLog] Clicking on sub menu
[log] CLICK on L(1906, 991)@S(0) [0,0 1920X1080]
For generating user logs , you have mentioned the steps in Point2 of comment#1 ["usage: see the method org.sikuli.
But i could not find "user" in "org.sikuli.basics"
Could you please provide a sample code to add these custom logs in to my test script.
Thanks & Regards
Deepa
Revision history for this message
![]() |
#12 |
I just realised, that in the current implementation, the logs from Sikuli and the user logs go to different files if logging to file is switched on.
So the only possibility, to solve your problem currently is to just log to sys-out and redirect the output to a file. For this you have to run your app from command line.
the simplest usage:
Debug.user("some message");
or adding some variables
String theImage = "some-image.png"
s.click(theImage)
Debug.user("we clicked %s at %s", theImage, s.getLastMatch())
the command line
java -jar myapp.jar >log.txt
Revision history for this message
![]() |
#13 |
version 1.2 will have a completely new logging concept based on logback/slf4j
Revision history for this message
![]() |
#14 |
Thanks RaiMan for the nice explanation.
I will wait for the version 1.2 for new logging concepts.
Can you help with this problem?
Provide an answer of your own, or ask DeepaKiran for more information if necessary.