If you've read the wiki page that Niclas pointed out, you'll notice that
the use of Log4j's api will remain *exactly* the same. The Log4j's api
is basically reimplemented to use an OSGi logging service internally. So
you don't actually need to get the org.apache.log4j.Logger instance as
an OSGi service. The wiki page contains the details on how to use it.
Just make sure that you don't have any other log4j jar files in your
bundle's classpath.
Makas
Pierre Parrend wrote:
> This makes me understand better how the pax logger works. I still have a
> question: what is the role of the pax own logging api, does it bring something
> that the other logger do not have ?
>
> Actually, I am looking for the following:
> - I already have some osgi bundles that use log4j
> - I would like to define a central logging configuration for all my bundles
> - I do not want to re invent the wheel
>
> so pax seems to be quite adapted to my needs, but seems to lack on feature :
> - provide a org.apache.log4j.Logger instance as a service, that could be
> accessed from all other bundles. Such a service would be easy to configure
> with
> its own properties.
>
> however, it does not seem that the log4j Logger is currently available as a
> service on pax. Does it helps if I write the code for this ? Would it be
> possible to integrate it in Pax ? (I do not claim it is difficult, but from my
> view I could be usefull ;-))
>
> regards,
>
> Pierre
>
>
> Quoting Makas Tzavellas <[EMAIL PROTECTED]>:
>
>
>> The bundles that you *need* are pax-logging-api.jar and
>> pax-logging-service.jar. And depending on which logging api you use,
>> you'll have to include the pax-logging-(logger-type).jar for it. E.g If
>> you use commons-logging api, you'll include pax-logging-jcl.jar or if
>> you're using log4j api, you'll include pax-logging-log4j.jar instead.
>>
>> As an alternative, you can use the org.osgi.service.log.LogService
>> interface, and you would only need the first 2 jar files mentioned.
>>
>> AFAIK, to configure your logging output, you'll need to use
>> ConfigurationAdmin to find a ManagedService with the SERVICE_PID of
>> org.ops4j.pax.logging to set the logging output following the Log4j's
>> properties key and value.
>>
>> E.g
>> properties.put( "log4j.logger.com.acme", "TRACE, A1" );
>> properties.put( "log4j.appender.A1", "org.apache.log4j.FileAppender" );
>> properties.put( "log4j.appender.A1.File", "com.acme.log" );
>> properties.put( "log4j.appender.A1.layout",
>> "org.apache.log4j.PatternLayout" );
>> properties.put( "log4j.appender.A1.layout.ConversionPattern", "%d %-5p
>> [%t] %C{2} (%F:%L) - %m%n" );
>>
>> And pass that properties into the Configuration.update() method.
>>
>> Hope this helps.
>>
>> Makas
>>
>> Pierre Parrend wrote:
>>
>>> okay, fine, it compiles now. Does it not exist a Howto that tells how to
>>> quickly make the pax logger available on a OSGi platform ? currently it
>>>
>> seems
>>
>>> that the only way is to try and look what are the missing dependencies ...
>>>
>>> pierre
>>>
>>> Quoting Makas Tzavellas <[EMAIL PROTECTED]>:
>>>
>>>
>>>
>>>> The testcase is now fixed. LoggingServiceFactory no longer implements
>>>> the ManagedServiceFactory, hence the compile error.
>>>>
>>>> Pierre Parrend wrote:
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>> I'm planning to use PAX for logging on OSGi. unfortunately, it seems
>>>>>
>> the
>>
>>>>> compile stage have some bugs in the
>>>>> org.ops4j.pax.logging.internal.LoggingServiceFactory class, namely (at
>>>>>
>> mvn
>>
>>>>> install; code checked out from subversion this morning 13.11.06):
>>>>>
>>>>> - lacks the public fields LOG4J_LOGGER_NAME, LOG4J_CONFIG_FILE
>>>>> - lacks the constructor LoggingServiceFactory( ConfigFactory,
>>>>> PaxLoggingService)
>>>>> - lacks the method method updated( String, Hashtable<String, String>)
>>>>>
>>>>> Is there a clean LoggingServiceFactory lying somewhere ?
>>>>> you will find the error output just below,
>>>>>
>>>>> best regards,
>>>>>
>>>>> Pierre
>>>>>
>>>>> -----
>>>>>
>>>>>
>>>>>
> /home/pierre/downloads/logging/ops4j/pax/logging/service/src/test/java/org/ops4j/pax/logging/test/Log4jServiceFactoryTestCase.java:[56,45]
>
>>>
>>>
>>>>> cannot find symbol
>>>>> symbol : variable LOG4J_LOGGER_NAME
>>>>> location: class org.ops4j.pax.logging.internal.LoggingServiceFactory
>>>>>
>>>>>
>>>>>
>>>>>
> /home/pierre/downloads/logging/ops4j/pax/logging/service/src/test/java/org/ops4j/pax/logging/test/Log4jServiceFactoryTestCase.java:[57,45]
>
>>>
>>>
>>>>> cannot find symbol
>>>>> symbol : variable LOG4J_CONFIG_FILE
>>>>> location: class org.ops4j.pax.logging.internal.LoggingServiceFactory
>>>>>
>>>>>
>>>>>
>>>>>
> /home/pierre/downloads/logging/ops4j/pax/logging/service/src/test/java/org/ops4j/pax/logging/test/Log4jServiceFactoryTestCase.java:[63,40]
>
>>>
>>>
>>>>> cannot find symbol
>>>>> symbol : constructor
>>>>>
>>>>>
>>>>>
> LoggingServiceFactory(org.ops4j.pax.logging.internal.ConfigFactory,org.ops4j.pax.logging.PaxLoggingService)
>
>>>
>>>
>>>>> location: class org.ops4j.pax.logging.internal.LoggingServiceFactory
>>>>>
>>>>>
>>>>>
>>>>>
> /home/pierre/downloads/logging/ops4j/pax/logging/service/src/test/java/org/ops4j/pax/logging/test/Log4jServiceFactoryTestCase.java:[107,15]
>
>>>
>>>
>>>>> cannot find symbol
>>>>> symbol : method
>>>>>
>>>>>
>>>>>
> updated(java.lang.String,java.util.Hashtable<java.lang.String,java.lang.String>)
>
>>>
>>>
>>>>> location: class org.ops4j.pax.logging.internal.LoggingServiceFactory
>>>>>
>>>>> ----------
>>>>>
>>>>>
>>>>>
>>>>>
>>>> _______________________________________________
>>>> general mailing list
>>>> [email protected]
>>>> http://lists.ops4j.org/mailman/listinfo/general
>>>>
>>>>
>>>>
>>>
>>>
>> _______________________________________________
>> general mailing list
>> [email protected]
>> http://lists.ops4j.org/mailman/listinfo/general
>>
>>
>
>
>
_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general