Skip to content

Commit

Permalink
fix #339 so we now have a maximum log cache size (which defaults to 1…
Browse files Browse the repository at this point in the history
…000) so we can leave the log UI up for a long time and it will trim the earlier logs
  • Loading branch information
jstrachan committed May 13, 2013
1 parent 13b68cf commit 3ba9e2d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
17 changes: 14 additions & 3 deletions hawtio-web/src/main/webapp/app/core/html/preferences.html
Expand Up @@ -25,7 +25,18 @@
</div>
</form>

<strong>git</strong>
<strong>Logs</strong>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="logCacheSize" title="The number of log messages to keep in the browser">Log cache size</label>

<div class="controls">
<input id="logCacheSize" type="number" ng-model="logCacheSize"/>
</div>
</div>
</form>

<strong>Git</strong>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="gitUserName" title="The user name to be used when making changes to files with the source control system">User Name</label>
Expand All @@ -43,7 +54,7 @@
</div>
</form>

<strong>activemq</strong>
<strong>ActiveMQ</strong>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="activemqUserName" title="The user name to be used when connecting to the broker">User Name</label>
Expand All @@ -64,7 +75,7 @@

<!-- TODO Split into its file and include as a partial -->
<div ng-controller="CodeEditor.PreferencesController">
<strong>Code Editor</strong>
<strong>Editor</strong>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="theme" title="The default theme to be used by the code editor">Theme</label>
Expand Down
23 changes: 21 additions & 2 deletions hawtio-web/src/main/webapp/app/core/js/preferences.ts
Expand Up @@ -6,6 +6,14 @@ module Core {
$scope.url = localStorage['url'];
$scope.autoRefresh = localStorage['autoRefresh'] === "true";

var defaults = {
logCacheSize: 1000
};

var converters = {
logCacheSize: parseInt
};

console.log("AutoRefresh", $scope.autoRefresh);

$scope.$watch('updateRate', () => {
Expand All @@ -21,15 +29,26 @@ module Core {
console.log("AutoRefresh", $scope.autoRefresh);
});

var names = ["gitUserName", "gitUserEmail", "activemqUserName", "activemqPassword"];
var names = ["gitUserName", "gitUserEmail", "activemqUserName", "activemqPassword", "logCacheSize"];

angular.forEach(names, (name) => {
$scope[name] = localStorage[name] || "";
$scope[name] = localStorage[name];
var converter = converters[name];
if (converter) {
$scope[name] = converter($scope[name]);
}
if (!$scope[name]) {
$scope[name] = defaults[name] || "";
}

$scope.$watch(name, () => {
var value = $scope[name];
if (value) {
localStorage[name] = value;
}
});
});

console.log("logCacheSize " + $scope.logCacheSize);
}
}
8 changes: 8 additions & 0 deletions hawtio-web/src/main/webapp/app/log/js/helpers.ts
Expand Up @@ -56,4 +56,12 @@ module Log {
}
return line;
}

export function getLogCacheSize(localStorage) {
var text = localStorage['logCacheSize'];
if (text) {
return parseInt(text);
}
return 1000;
}
}
12 changes: 11 additions & 1 deletion hawtio-web/src/main/webapp/app/log/js/logs.ts
Expand Up @@ -8,7 +8,7 @@ module Log {
level: string;
}

export function LogController($scope, $location, workspace:Workspace) {
export function LogController($scope, $location, localStorage, workspace:Workspace) {
$scope.logs = [];
$scope.filteredLogs = [];
$scope.selectedItems = [];
Expand All @@ -22,6 +22,7 @@ module Log {
$scope.toTime = 0;
$scope.queryJSON = { type: "EXEC", mbean: logQueryMBean, operation: "logResultsSince", arguments: [$scope.toTime], ignoreErrors: true};


$scope.logClass = (log) => {
return logLevelClass(log['level']);
};
Expand Down Expand Up @@ -126,6 +127,7 @@ module Log {
}
}
if (logs) {
var maxSize = getLogCacheSize(localStorage);
var counter = 0;
logs.forEach((log:ILog) => {
if (log) {
Expand All @@ -136,6 +138,14 @@ module Log {
}
}
});
if (maxSize > 0) {
var size = $scope.logs.length;
if (size > maxSize) {
// lets trim the log size
var count = size - maxSize;
$scope.logs.splice(0, count);
}
}
if (counter) {
refilter();
$scope.$apply();
Expand Down

0 comments on commit 3ba9e2d

Please sign in to comment.