Permalink
Browse files

* added pom.xml for maven build

* added facade for slf4j which will be default when running jruby and having the respective libraries in place
  • Loading branch information...
1 parent 9224a55 commit 1ee0e31d8fd4f15905c5f56348167b72c38a5787 @mkristian committed May 9, 2010
Showing with 177 additions and 8 deletions.
  1. +6 −8 lib/slf4r.rb
  2. +41 −0 lib/slf4r/java_logger.rb
  3. +130 −0 pom.xml
View
@@ -1,8 +1,6 @@
-require 'rubygems'
-require 'pathname'
-
-dir = Pathname(__FILE__).dirname.expand_path + 'slf4r'
-
-require dir + 'version'
-require dir + 'logger'
-require dir + 'ruby_logger'
+require 'slf4r/logger'
+begin
+ require 'slf4r/java_logger'
+rescue
+ require 'slf4r/ruby_logger'
+end
View
@@ -0,0 +1,41 @@
+require 'java'
+module Slf4r
+ class LoggerFacade
+
+ protected
+
+ def format(exception)
+ (": #{exception.message}:\n\t#{exception.backtrace.join("\n\t") if exception.backtrace }") if exception
+ end
+
+ public
+
+ attr_reader :name
+
+ attr_reader :logger
+
+ def initialize(name)
+ @name = name
+ @logger = org.slf4j.LoggerFactory.getLogger(name.to_s.sub(/^::/, '').gsub(/::/, '.'))
+ end
+
+ [:debug, :info, :warn, :error].each do |level|
+ class_eval <<-CODE
+ def #{level}?
+ @logger.is_#{level}_enabled
+ end
+
+ def #{level}(msg = nil, exception = nil)
+ if(@logger.is_#{level}_enabled)
+ msg, exception = yield if block_given?
+ if(exception.type == NativeException)
+ @logger.#{level}(msg, exception.cause)
+ else
+ @logger.#{level}("\#{msg}\#{format(exception)}")
+ end
+ end
+ end
+CODE
+ end
+ end
+end
View
130 pom.xml
@@ -0,0 +1,130 @@
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>rubygems</groupId>
+ <artifactId>slf4r</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ <packaging>gem</packaging>
+ <name>Slf4r</name>
+ <description>Slf4r provides a uniform interface for instantiating und using of a logger</description>
+
+ <repositories>
+ <repository>
+ <id>rubygems</id>
+ <releases>
+ <updatePolicy>never</updatePolicy>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <url>http://rubygems.org/gems</url>
+ <layout>gem</layout>
+ </repository>
+ </repositories>
+
+ <url>http://github.com/mkristian/slf4r</url>
+ <scm>
+ <connection>scm:git:git://github.com/mkristian/slf4r.git</connection>
+ <developerConnection>scm:git:git@github.com:mkristian/slf4r.git</developerConnection>
+ <url>http://github.com/mkristian/slf4r</url>
+ </scm>
+ <licenses>
+ <license>
+ <name>MIT</name>
+ <url>http://www.opensource.org/licenses/mit-license.php</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <developers>
+ <developer>
+ <id>mkristian</id>
+ <name>Kristian Meier</name>
+ <email>m.kristian@web.de</email>
+ <timezone>IST</timezone>
+ </developer>
+ </developers>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>rubygems</groupId>
+ <artifactId>rspec</artifactId>
+ <version>1.3.0</version>
+ <type>gem</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>rubygems</groupId>
+ <artifactId>logging</artifactId>
+ <version>1.4.1</version>
+ <type>gem</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>rubygems</groupId>
+ <artifactId>log4r</artifactId>
+ <version>1.1.7</version>
+ <type>gem</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>de.saumya.mojo</groupId>
+ <artifactId>gem-maven-plugin</artifactId>
+ <version>${jruby.plugins.version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>de.saumya.mojo</groupId>
+ <artifactId>rspec-maven-plugin</artifactId>
+ <version>${jruby.plugins.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <specSourceDirectory>${basedir}/spec</specSourceDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>de.saumya.mojo</groupId>
+ <artifactId>jruby-maven-plugin</artifactId>
+ <version>${jruby.plugins.version}</version>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>jruby</goal>
+ </goals>
+ <configuration>
+ <script>
+ puts "module Slf4r"
+ puts " VERSION = '${project.version}'".sub(/-SNAPSHOT/, '')
+ puts "end"
+ </script>
+ <outputFile>lib/slf4r/version.rb</outputFile>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <jruby.plugins.version>0.11.1</jruby.plugins.version>
+ </properties>
+</project>

0 comments on commit 1ee0e31

Please sign in to comment.