Skip to main content

Welcome to Geoff Hayward's Weblog

Commenting on Java, JavaFX, Java EE, Joomla, and IoT.

I would like to share a simple Windows Batch script that I made. The Batch script changes the WildFly's logging level quickly and easily. It is as easy as running change-logging-level.cmd --file-debug --console-error

change-logging-level.cmd

:: Name:     change-logging-level.cmd
:: Purpose:  Set's the logging level to very low or the setting given as an argument
:: Author:   geoffhayward.eu
:: Revision: August 2016 - initial version
@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET NOPAUSE=true
SET ME=%~n0
SET SCRIPT=%TEMP%\%ME%-%DATE:/=-%.txt
SET CON_LEVEL=ERROR
SET FILE_LEVEL=ERROR

:parse_args
IF NOT "%~1"=="" (
		IF "%~1"=="--all" (
		SET CON_LEVEL=ALL
		SET FILE_LEVEL=ALL
	)
	IF "%~1"=="--console-all" (
		SET CON_LEVEL=ALL
	)
	IF "%~1"=="--file-all" (
		SET FILE_LEVEL=ALL
	)
	IF "%~1"=="--config" (
		SET CON_LEVEL=CONFIG
		SET FILE_LEVEL=CONFIG
	)
	IF "%~1"=="--console-config" (
		SET CON_LEVEL=CONFIG
	)
	IF "%~1"=="--file-config" (
		SET FILE_LEVEL=CONFIG
	)
	IF "%~1"=="--debug" (
		SET CON_LEVEL=DEBUG
		SET FILE_LEVEL=DEBUG
	)
	IF "%~1"=="--console-debug" (
		SET CON_LEVEL=DEBUG
	)
	IF "%~1"=="--file-debug" (
		SET FILE_LEVEL=DEBUG
	)
	IF "%~1"=="--error" (
		SET CON_LEVEL=ERROR
		SET FILE_LEVEL=ERROR
	)
	IF "%~1"=="--console-error" (
		SET CON_LEVEL=ERROR
	)
	IF "%~1"=="--file-error" (
		SET FILE_LEVEL=ERROR
	)
	IF "%~1"=="--fatal" (
		SET CON_LEVEL=FATAL
		SET FILE_LEVEL=FATAL
	)
	IF "%~1"=="--console-fatal" (
		SET CON_LEVEL=FATAL
	)
	IF "%~1"=="--file-fatal" (
		SET FILE_LEVEL=FATAL
	)
	IF "%~1"=="--fine" (
		SET CON_LEVEL=FINE
		SET FILE_LEVEL=FINE
	)
	IF "%~1"=="--console-fine" (
		SET CON_LEVEL=FINE
	)
	IF "%~1"=="--file-fine" (
		SET FILE_LEVEL=FINE
	)
	IF "%~1"=="--finer" (
		SET CON_LEVEL=FINER
		SET FILE_LEVEL=FINER
	)
	IF "%~1"=="--console-finer" (
		SET CON_LEVEL=FINER
	)
	IF "%~1"=="--file-finer" (
		SET FILE_LEVEL=FINER
	)
	IF "%~1"=="--finest" (
		SET CON_LEVEL=FINEST
		SET FILE_LEVEL=FINEST
	)
	IF "%~1"=="--console-finest" (
		SET CON_LEVEL=FINEST
	)
	IF "%~1"=="--file-finest" (
		SET FILE_LEVEL=FINEST
	)
	IF "%~1"=="--info" (
		SET CON_LEVEL=INFO
		SET FILE_LEVEL=INFO
	)
	IF "%~1"=="--console-info" (
		SET CON_LEVEL=INFO
	)
	IF "%~1"=="--file-info" (
		SET FILE_LEVEL=INFO
	)
	IF "%~1"=="--off" (
		SET CON_LEVEL=OFF
		SET FILE_LEVEL=OFF
	)
	IF "%~1"=="--console-off" (
		SET CON_LEVEL=OFF
	)
	IF "%~1"=="--file-off" (
		SET FILE_LEVEL=OFF
	)
	IF "%~1"=="--trace" (
		SET CON_LEVEL=TRACE
		SET FILE_LEVEL=TRACE
	)
	IF "%~1"=="--console-trace" (
		SET CON_LEVEL=TRACE
	)
	IF "%~1"=="--file-trace" (
		SET FILE_LEVEL=TRACE
	)
	IF "%~1"=="--warn" (
		SET CON_LEVEL=WARN
		SET FILE_LEVEL=WARN
	)
	IF "%~1"=="--console-warn" (
		SET CON_LEVEL=WARN
	)
	IF "%~1"=="--file-warn" (
		SET FILE_LEVEL=WARN
	)
	IF "%~1"=="--warning" (
		SET CON_LEVEL=WARNING
		SET FILE_LEVEL=WARNING
	)
	IF "%~1"=="--console-warning" (
		SET CON_LEVEL=WARNING
	)
	IF "%~1"=="--file-warning" (
		SET FILE_LEVEL=WARNING
	)
	SHIFT
	GOTO :parse_args
)


ECHO batch > %SCRIPT%
ECHO /subsystem=logging/console-handler=CONSOLE:change-log-level(level=%CON_LEVEL%)>> %SCRIPT%
ECHO /subsystem=logging/periodic-rotating-file-handler=FILE:change-log-level(level=%CON_LEVEL%)>> %SCRIPT%
ECHO run-batch >> %SCRIPT%

 
CALL %JBOSS_HOME%\bin\jboss-cli.bat -c --file="%TEMP%\%ME%-%DATE:/=-%.txt"

ENDLOCAL

This version of the Batch script is designed for Windows based dev environments, with WildFly as the target dev Java EE application container. The Batch script creates a simple JBoss CLI script and then sends that script into JBoss CLI. Note %JBOSS_HOME% needs to be set as an environment variable.

Calling this 'change-logging-level.cmd' script without any arguments will set WildFly's logging level down to 'ERROR' for both the console and file logging. Supplying arguments will override the default, for example change-logging-level.cmd --fine will immediately (except long running translations), set all logging to 'fine'.



Read

In an earlier post this year, 'Convert an ArrayList to an Array in Java', I commented on a way to convert an ArrayList to an Array in Java. Here is the example code from the earlier post.

List<String> results = new ArrayList<>();
...
results.toArray(new String[results.size()]);

This earlier way works fine, however it's old school. Here is the Java 8 Lambda way to convert an ArrayList to an Array:

Long[] longArray = longArrayList.stream()
    .map(Long::new)
    .toArray(Long[]::new);

This example works by mapping a new object for each item in the ArrayList's stream to the new stream, and then collecting that stream as an array.



Read

I am very happy to be attending Devoxx Poland 2016; I enjoyed Devoxx Poland last year very much. As well as Krakow.

This year I am looking forward to talks on: Java 9 Flow API; Angular 2; Microservices; lambdas; and many other topics. But, worryingly there does not seem to be a single talk with "Java EE" in the title. Like last year Devoxx Poland has attracted many great speakers.

Also, the food last year was delicious, so I hoping for the same this year.

Here is Devoxx 2015 video



Read

This is a note on a simple regular expression to GREP for exceptions in a group of log files.

I have been debugging an issue unsure of what to look for. Of course 'Exception' on its own is not a great search term. Using a negative look-behind made the difference in trying to narrow down on what to look for. The look-behind made it possible to rule out the name of some of the exceptions that are not important to the issue at hand.

(?<!Faces|FileNotFound|Configuration)Exception


Read

I have been experimenting with the Twitter Bower package manager as part of the tech stack to be used with a Java EE JSF project.

This post is a note on how I set up the Web Application project to use the Bower package manager.

I began by setting up a new Mavan Web Application. I used the NetBeans 'New Project' wizard. Once the new Web Application project was created I added JavaServer Faces to the project via NetBeans' Properties > Framework menu.

Next I added a .bowerrc file to the root of the webapp as:

{
  "directory": "resources/components"
}

This .bowerrc file changes the default location that Bower will store the components it downloads. This change made Bower fit with a Mavan Web Application folder structure. Next I added a bower.json file to the root of the webapp.

{
  "name": "bower-setup-test",
  "authors": [
    "Geoffrey Hayward"
  ],
  "private": true
}

The bower.json file keeps a record of each dependency and its version that is added to the project. See the bower.json spec for details.

Then from the root of the webapp I ran the command: bower install bootstrap --save. The --save saved the dependency to bower.json file.

Why Bower? Good question. To reduce the size of the tracked GIT repository and to make the web component libraries explicit. Each time a file is forked from the dependency, such as a bootstrap LESS variables file, you add it to the bower.json ignore property. Likewise you then begin tracking the forked file in GIT. Everything that is managed by Bower (that is not forked) is in (or should be in) the .gitignore file.

My Thoughts: Post Experiment

My thoughts to using Bower with a Java EE JSF project are Bower adds complexity to a Java EE JSF project that may not bring any value. But, with that said Bower certainly would come in handy for a front-end framework heavy project; particularly when some control over what should and should not be edited is needed. In other words I am undecided for now, but have no plans to start using Bower just yet in this context.



Read

Responsive Media

With the ResponsiveMedia plugin for Joomla it is easy to add 3rd party content from YouTube, Vimeo, and Instagram right in to any Joomla! article.

ResponsiveMedia