wicket-clientside-logging is a helper library that allows javascript logging on client side, all log messages will be stored on server side too.
- Wicket 7.x: 0.4.0
- Wicket 6.x: 0.3.3
wicket-clientside-logging is available in Maven central repository.
core maven dependency:
<dependency>
<groupId>de.agilecoders.wicket</groupId>
<artifactId>wicket-clientside-logging</artifactId>
<version>0.4.0</version>
</dependency>
// Install settings class; best place to do this is in Application#init()
ClientSideLogging.install(Application.get());
// add the ClientSideLoggingBehavior to your page
public class MyPage extends Page {
public MyPage(PageParameters params) {
super(params);
add(new ClientSideLoggingBehavior());
}
}
// use Log object or Wicket.Log on client side
function myFunc() {
Log.error("this will be sent to server.");
Wicket.Log.error("this too.");
$.Log.error("also this is sent to server...");
}
Supported log methods: error
, warn
, info
, debug
and trace
A log method won't do anything as long as you don't use a log level that contains the level of the method. The default log level is set to error
which means that methods like warn
, info
, debug
and trace
won't send data to the server.
There are some default arguments that you can override.
Configuration of ClientSideLoggingSettings:
new ClientSideLoggingSettings()
.level(level) // sets the log level for client side logger (default: error)
.debug(bool) // whether to activate debug mode or not; in debug mode all log messages will be written to console.log too (default: false)
.logger(logger) // defines the logger that is used on server side (default: slf4j)
.stacktrace(bool) // whether to collect stacktrace on server side or not (default: false)
.cleaner(cleaner) // a cleaner is responsible for cleaning log messages; (default: remove all [\r\n\t])
Configuration of ClientSideLoggingBehavior:
ClientSideLoggingBehavior.newBuilder()
.replaceWicketLog() // whether to replace Wicket.Log or not (default: true)
.replaceWindowOnError() // whether to replace window.onerror or not (default: true)
.wrapWicketLog() // whether to wrap Wicket.Log or not, all calls to Wicket.Log will be sent to server and to original Wicket.Log object (default: false)
.wrapWindowOnError() // whether to wrap window.onerror or not, all window.onerror events will be sent to server and to original window.onerror handler (default: false)
.logAdditionalErrors() // whether to log all window.onerror messages or just the first one (default: true)
.flushMessagesOnUnload() // If set to true all log messages will be sent synchronously to server when a page unload event is fired (default: true)
.collectClientInfos() // If set to true some client data will be collected too; user-agent, screen/window size, ajaxBaseUrl (default: true)
.collectionTimer(duration) // Sets the interval between two server calls, all messages between will be queued, this is only used if collectionType is set to "timer" (default: 5000)
.maxQueueSize(size) // Sets the maximum queue size, if max size is exceeded all messages will be sent to server (default: 5)
.maxEntriesPerPage(size) // Sets the maximum number of log entries can be sent to server, if max size is exceeded all messages will be dropped (default: 10)
.collectionType(type) // Sets the collection type (default: single, other: timer, size, unload)
.customFilter(string) // Sets the custom client side filter for log events (see QA: How to add client side filter?)
.loggerName(name) // Sets the logger name that is used on client side, e.g. name="Log": Log.info('message'); (default: Log)
.build();
or you can use a string specification to build a ClientSideLoggingBehavior
(since 0.1.2):
ClientSideLoggingBehavior.newBuilder("collectClientInfos=false,collectionType=Timer,collectionTimer=100 seconds").build();
public class MyApplication extends WebApplication {
protected void init() {
ClientSideLoggingSettings settings = new ClientSideLoggingSettings();
settings.logger(new IClientLogger.DefaultClientLogger(settings.id()) {
protected String newLogMessage(String level, ClientSideLogObject logObject, ClientInfos clientInfos, ILogCleaner cleaner) {
return String.format("[%s] %s; Timestamp: %s; UserAgent: %s; WindowSize: %s",
cleaner.toCleanPath(clientInfos.ajaxBaseUrl()),
logObject.message(),
logObject.timestamp(),
cleaner.clean(clientInfos.userAgent()),
cleaner.clean(clientInfos.windowSize()));
}
});
ClientSideLogging.install(this, settings);
}
}
public class MyPage extends WebPage {
public MyPage(PageParameters params) {
super(params);
add(ClientSideLoggingBehavior.newBuilder().build(MyClientSideLoggingBehavior.class));
}
public static class MyClientSideLoggingBehavior extends ClientSideLoggingBehavior {
public MyClientSideLoggingBehavior(final Map<String, Object> data) {
super(data);
}
}
}
public class MyPage extends WebPage {
public MyPage(PageParameters params) {
super(params);
add(ClientSideLoggingBehavior.newBuilder()
.customFilter("return event.message.indexOf('Error') > -1") // sends all messages that contains "Error" to server
.customFilter("globalFilterFunction") // uses the function window.globalFilterFunction(event)
.customFilter("my.namespace.filterFunction") // uses the function my.namespace.filterFunction(event)
.build(MyClientSideLoggingBehavior.class));
}
public static class MyClientSideLoggingBehavior extends ClientSideLoggingBehavior {
public MyClientSideLoggingBehavior(final Map<String, Object> data) {
super(data);
}
}
}
Have a bug? Please create an issue here on GitHub!
https://github.com/l0rdn1kk0n/wicket-clientside-logging/issues
- Keep up to date on announcements and more by following me @l0rdn1kk0n on Twitter
- how to use Wicket Clientside Logging? Read the documentation on https://github.com/l0rdn1kk0n/wicket-clientside-logging/wiki.
- read more on my blog.
Wicket-Clientside-Logging will be maintained under the Semantic Versioning guidelines as much as possible.
Releases will be numbered with the follow format:
<major>.<minor>.<patch>
And constructed with the following guidelines:
- Breaking backward compatibility bumps the major
- New additions without breaking backward compatibility bumps the minor
- Bug fixes and misc changes bump the patch
For more information on SemVer, please visit http://semver.org/.
Copyright 2012 AgileCoders.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.