Skip to content

Commit

Permalink
Moving metric logger from jive-utils to its own repo and upgraded to …
Browse files Browse the repository at this point in the history
…log4j 2.1
  • Loading branch information
Jonathan Colt committed Jan 22, 2015
1 parent 71a03c9 commit 59f23fc
Show file tree
Hide file tree
Showing 53 changed files with 6,017 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/.bash*
/.j-log
/.ssh/
/.m2/
/.vim*
*.iml
*.ipr
*.iws
.repository/
.vagrant
*.log
.idea/
.classpath
.settings/
.project
*.class
nbactions.xml
target/
.checkstyle
.checkstyle-cachefile
75 changes: 75 additions & 0 deletions code/com/jivesoftware/os/mlogger/core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.jivesoftware.os.mlogger.inheritance.poms</groupId>
<artifactId>shared-lib-build-management</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>../inheritance-poms/shared-lib-build-management/pom.xml</relativePath>
</parent>
<groupId>com.jivesoftware.os.mlogger</groupId>
<artifactId>core</artifactId>
<properties>
<module.type>shared_lib</module.type>
</properties>

<dependencies>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng-common</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.jivesoftware.os.mlogger.core;

import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

// Source ripped from log4j 1.2.16
/**
Formats a {@link java.util.Date} in the format "HH:mm:ss,SSS" for example,
"15:49:37,459".
@author Ceki G&uuml;lc&uuml;
@author Andrew Vajoczki
@since 0.7.5
*/
public class AbsoluteTimeDateFormat extends DateFormat {

private static final long serialVersionUID = -388856345976723342L;

/**
String constant used to specify {@link
org.apache.log4j.helpers.AbsoluteTimeDateFormat} in layouts. Current
value is <b>ABSOLUTE</b>. */
public final static String ABS_TIME_DATE_FORMAT = "ABSOLUTE";

/**
String constant used to specify {@link
org.apache.log4j.helpers.DateTimeDateFormat} in layouts. Current
value is <b>DATE</b>.
*/
public final static String DATE_AND_TIME_DATE_FORMAT = "DATE";

/**
String constant used to specify {@link
org.apache.log4j.helpers.ISO8601DateFormat} in layouts. Current
value is <b>ISO8601</b>.
*/
public final static String ISO8601_DATE_FORMAT = "ISO8601";

public
AbsoluteTimeDateFormat() {
setCalendar(Calendar.getInstance());
}

public
AbsoluteTimeDateFormat(TimeZone timeZone) {
setCalendar(Calendar.getInstance(timeZone));
}

private static long previousTime;
private static char[] previousTimeWithoutMillis = new char[9]; // "HH:mm:ss."

/**
Appends to <code>sbuf</code> the time in the format
"HH:mm:ss,SSS" for example, "15:49:37,459"
@param date the date to format
@param sbuf the string buffer to write to
@param fieldPosition remains untouched
*/
public
StringBuffer format(Date date, StringBuffer sbuf,
FieldPosition fieldPosition) {

long now = date.getTime();
int millis = (int) (now % 1000);

if ((now - millis) != previousTime || previousTimeWithoutMillis[0] == 0) {
// We reach this point at most once per second
// across all threads instead of each time format()
// is called. This saves considerable CPU time.

calendar.setTime(date);

int start = sbuf.length();

int hour = calendar.get(Calendar.HOUR_OF_DAY);
if (hour < 10) {
sbuf.append('0');
}
sbuf.append(hour);
sbuf.append(':');

int mins = calendar.get(Calendar.MINUTE);
if (mins < 10) {
sbuf.append('0');
}
sbuf.append(mins);
sbuf.append(':');

int secs = calendar.get(Calendar.SECOND);
if (secs < 10) {
sbuf.append('0');
}
sbuf.append(secs);
sbuf.append(',');

// store the time string for next time to avoid recomputation
sbuf.getChars(start, sbuf.length(), previousTimeWithoutMillis, 0);

previousTime = now - millis;
} else {
sbuf.append(previousTimeWithoutMillis);
}

if (millis < 100) {
sbuf.append('0');
}
if (millis < 10) {
sbuf.append('0');
}

sbuf.append(millis);
return sbuf;
}

/**
This method does not do anything but return <code>null</code>.
*/
public
Date parse(String s, ParsePosition pos) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2013 Jive Software, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License 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.
*/
package com.jivesoftware.os.mlogger.core;

import java.util.concurrent.atomic.AtomicLong;

public final class AtomicCounter implements AtomicCounterMXBean {

private ValueType type;
private AtomicLong value = new AtomicLong(0L);

public AtomicCounter() {
}

public AtomicCounter(ValueType type) {
this.type = type;
}

public String toJsonString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("\"type\":\"");
sb.append(type.name());
sb.append("\",");
sb.append("\"value\":");
sb.append(value.get());
sb.append("}");
return sb.toString();
}

public ValueType getValueType() {
return type;
}

public void setType(ValueType type) {
this.type = type;
}

@Override
public long getValue() {
return value.get();
}

public void setValue(long value) {
this.value.set(value);
}

@Override
public String getType() {
return type.name();
}

public void reset() {
this.value.set(0);
}

public void inc() {
value.incrementAndGet();
}

public void inc(long amount) {
value.addAndGet(amount);
}

public void dec() {
value.decrementAndGet();
}

public void dec(long amount) {
value.addAndGet(-amount);
}

public void set(long value) {
this.value.set(value);
}

public long getCount() {
return value.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2013 Jive Software, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License 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.
*/
package com.jivesoftware.os.mlogger.core;

public interface AtomicCounterMXBean {

public long getValue();

public String getType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2013 Jive Software, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License 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.
*/
package com.jivesoftware.os.mlogger.core;

import java.util.concurrent.Callable;

/**
* Interface to generalize tracking info around a method call.
*
* @author jonathan
*/
public interface CallMonitor {

public <V> V call(Callable<V> callable) throws Exception;
}
Loading

0 comments on commit 59f23fc

Please sign in to comment.