Echo tasks have a logging level associated with them, and I've been able to use this to turn off certain debug messages by default, like echoing the CLASSPATH before every build.
That's great, except now I don't know how to get the debug messages to show up at all, via a command-line argument. Everything I've read refers to this, so it must be possible to set the log level, but I've no idea how to set it. Thanks!
I'm sure this is a simple thing I must have missed in the documentation, but a quite a few likely search queries returned no relevant results. A method to do this via Eclipse or IntelliJ would probably also be relevant.
Ant has several command line options for controlling its own verbosity (-quiet, -verbose), but these do not appear to correspond to log levels for <echo> tasks, and certainly cannot map to all possible log levels.
I see also that you can set the log level from within the build file, but that's not what I need.
According to this email, the following mappings are set up:
Cmd arg | Log level
---------+----------
<none> | INFO
-verbose | VERBOSE
-debug | DEBUG
-quiet | ???
-silent | ???
??? | ???
If you can find any more, please edit this post and add them to the list! In particular, I wonder what -quiet does to the logging level.
Also see Running Apache Ant page for details on arguments:
https://ant.apache.org/manual/running.html
Related
Currently, from my test execution, I see the first 10 lines of logs if the test has passed. I see the first n lines of logs if the test has failed. Ideally, I would like to see the last 100 lines of logs in Standard Error.
There are no settings setup in my Jenkins file, so I assume the current behavior is the default behavior of test execution. I need a way to change it.
I have tried ${BUILD_LOG, maxLines, escapeHtml} which gets me the logs that can be emailed to someone
I have tried messing around with System Logs
I would like my standard error to show the last n lines of logs
This is probably A way to do it(definitely not THE way or may not be the most efficient way)
Once the build completes do a curl to get the console logs, use something like this and store the file in the workspace: curl -isk -X -H "$CRUMB" $BUILD_URL/consoleText --user "$USER:$APITOKEN" -o consolelogs.txt
Then you can simply tail the file for the last 100 lines. eg: tail -100 <log file> > newLogfile
Combine it with Log parser plugin with a known string like ****start of logs**** and create a rule to parse it.
For point #1 refer this for getting the crumb, Jenkins API access
Update:
Just realized that the above approach may be difficult from within the same job, Either a down stream job can used or redirect the entire test logs to a file on the workspace without sending it to stdout and then use the tail and Log parser plugin to achieve the result
I'm invoking the <java> task using Ant to run a program that prints out some stuff to stdout that ultimately, I'd like the user to be able to copy-paste easily. However, each line of stdout is prefixed with [java], which makes things needlessly challenging for the user.
Is there some way to print just the output of System.out.println(...) without getting prefixed with [java]?
Set ANT_ARGS=-emacs, see ant FAQ:
Ant adds a "banner" with the name of the current task in front of all
logging messages - and there are no built-in regular expressions in
your editor that would account for this.
You can disable this banner by invoking Ant with the -emacs switch.
[...]
Also ant manual Running Apache Ant listing all cli options might be helpful :
-emacs, -e produce logging information without adornments
I would like Logger to have my custom logging level method implemented. For example i would like to call log.custom("custom level log"). According to the documentation it is possible but there is not enough hints for me. Can someone help me with understanding what does this command exactly do?
java -cp log4j-core-2.8.jar \
org.apache.logging.log4j.core.tools.Generate$ExtendedLogger \
com.mycomp.ExtLogger DIAG=350 NOTICE=450 VERBOSE=550 > com/mycomp/ExtLogger.java
What steps should I take after this command exits successfully? What exactly should I swap and where?
What the tool does is generate source code that you can include in your project. The intention is that you use the generated class instead of the standard Log4j2 Logger.
Before running the tool, you need to decide what to call your custom levels and where they rank, relative to the existing levels. The manual page shows a table with the int values of the built-in levels. The int value of your custom level will probably be in between these values.
In the quoted example, the tool will generate a class named ExtLogger in the com.mycomp package that extends the standard Log4j2 Logger with three custom levels (DIAG, NOTICE and VERBOSE). DIAG's int value is 350 so it sits between WARN (300) and INFO (400).
The tool writes the generated source code to the console. The example shows how you can redirect that output to a file. You can then include this file in your project.
Let's say I want to detect something in my code which I cannot check by tests.
e.g.:
- Go over my entire code base to detect there I have a space between brackets and curly brackets (using a regex).
- Go over my entire code base and detect style smells.
etc...
If one of these checks fails, I'd like to show a custom warning I define myself.
Is there anything like this in XCode?
Thanks.
I wrote a run script for Xcode that does exactly what you requested. It searches by regex for predefined "code smells" or "style smells" and warns you at compile time
Read the blog post, but the final script is here
#test if git exists.
command -v git > /dev/null 2>$1 || {exit 0}
#separate code smells with | i.e. (code_smell_1|code_smell_2)
KEYWORDS="(didDeselectRowAtIndexPath)"
git diff --name-only HEAD | grep "\.m" | xargs egrep -s --with-filename --line-number --only-matching "$KEYWORDS.*[^\/]*$" | perl -p -e "s/($KEYWORDS)/ warning: Are you sure you want to use \$1?\nTo remove this warning, append a comment at the end of this line \$1/"
This particular script searches for appearances of didDeselectRowAtIndexPath in the code, but you can change that to any string
You would need to create a project target that runs a script, which searches through your source files and does your checks (this is not trivial) and returns non-zero to indicate error.
Then make your app target dependent on this "check target" and the build will fail if the check fails.
If you want some indication of how you write this "check script" then I would be inclined to employ the clang static analyzer. However, unfortunately, scan-build is not installed as part of the Xcode Command Line tools, so you would need to use the LLVM-binaries in some way, or perhaps the macports version contains it.
For trivial checks, relating to spaces and other stylistic issues rather than real, live, code problems, then you will have to employ some other mechanism, and I have no idea how to start with that, sorry.
I'm running Ant with output fed to a log file:
ant -logfile file.txt target-name
I'd also like to print some simple progress information to the console though. The answer seems to be a BuildEvent listener that writes to the console every time a new target is hit, but the documentation explicitly states:
A listener must not access System.out and System.err directly since ouput on these streams is redirected by Ant's core to the build event system.
Did I miss something? Is there a way to do this?
Ant replaces the System.out & System.err streams to remap messages printed there through it's own logging system.
That said, you can still get access to the ACTUAL OS streams by using java.io.FileDescriptor#out
Actually, the answer is Log4jListener.
There is a sample log4j configuration for logging into both console and file shown in the above link. You can then use an <echo> task with an appropriate level parameter to selectively decide what gets printed to console.
Thanks for the answers! I'm slow, but this is still something that I'd like to get right.
I've managed to get something working more or less like I want using carej's suggested approach with the java.io.FileDescriptor#out stream and an Ant scriptdef like this:
<scriptdef name="progress-text" language="javascript" >
output = new java.io.PrintStream(new java.io.FileOutputStream(java.io.FileDescriptor.err))
output.println(self.text)
</scriptdef>
Now I'm just left wondering how wize is this approach? Is there inherit risk in using the underlying OS streams directly?
EDIT:
2 Points which might be useful to anyone else with a similar question:
This article has a very good description of the Ant I/O system: http://codefeed.com/blog/?p=68
java.lang.System does something very similar to set System.out and System.err in the first place.
All of this gave me a little more confidence in this approach.