You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Nicolas Peltier <np...@adobe.com.INVALID> on 2017/05/19 16:08:37 UTC

Re: Programmatically create a logger

Did track that work here [0] and successfully created a configuration very similar to what SlingLogPanel creates, however, it seems that

org.osgi.service.cm.Configuration.update(dict) from sling pipes bundle does not trigger LoggerManagedServiceFactory.updated

The only difference I see from the configuration is the bundleLocation property.

Am I right to assume this will somehow not work because the event comes from a different bundle?  

[0] https://issues.apache.org/jira/browse/SLING-6861
> On 28 Apr 2017, at 15:57, Nicolas Peltier <np...@adobe.com> wrote:
> 
> Hi,
> 
> For sling pipes, I’d like the possibility at each execution to create a log file. 
> Instead of re-inventing the wheel, I figured out I could just create a specific logger for the time being of the pipe execution, with configured log level & so on. 
> 
> Is it possible at all?
> 
> Nicolas
> 


Re: Programmatically create a logger

Posted by Nicolas Peltier <np...@adobe.com.INVALID>.
Hi Chetan,

Good catch indeed! Specifying the location did the trick. 

Now I’m on the next issue :-) once configured, it looks that there is some gap before output switch is done from default logger to the specified logger.

log.info(“before”);
config.update(...)
log.info(“after”);
…
log.info(“long after”);

Will only show “long after” and after that one. Worse, there are logs “in the middle” that are lost (not on the default logger, nor on the configured one). Is there a trick for a flush/wait that would help?

(Btw is there a way I can unit test those outputs at all?)

Nicolas
> On 23 May 2017, at 05:55, Chetan Mehrotra <ch...@gmail.com> wrote:
> 
> On Fri, May 19, 2017 at 9:38 PM, Nicolas Peltier
> <np...@adobe.com.invalid> wrote:
>> org.osgi.service.cm.Configuration.update(dict) from sling pipes bundle does not trigger LoggerManagedServiceFactory.updated
> 
> How are you creating the config instance from ConfigurationAdmin
> instance? You should use the listConfiguration approach [1] otherwise
> the config instance would get "bound" to the calling bundle [2] which
> would prevent that config from getting used by the Commons Log bundle
> 
> 
> Chetan Mehrotra
> [1] https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fapache%2Fsling%2Fblob%2Ftrunk%2Finstaller%2Ffactories%2Fconfiguration%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fsling%2Finstaller%2Ffactories%2Fconfiguration%2Fimpl%2FConfigUtil.java%23L191&data=02%7C01%7C%7C9373bf816b1c4c223e1408d4a18fa0df%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636311085627988743&sdata=vKgCoaYjNYdTfXjSOk12Hg1R5tHFshf0h4gqXTM%2Fb84%3D&reserved=0
> [2] https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fosgi.org%2Fjavadoc%2Fr4v42%2Forg%2Fosgi%2Fservice%2Fcm%2FConfigurationAdmin.html%23getConfiguration(java.lang.String&data=02%7C01%7C%7C9373bf816b1c4c223e1408d4a18fa0df%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636311085627988743&sdata=WHxtsSoaDuBR21lgq2E9HEyCQJmkduy%2BfTneSVh0oLI%3D&reserved=0)


Re: Programmatically create a logger

Posted by Chetan Mehrotra <ch...@gmail.com>.
On Fri, May 19, 2017 at 9:38 PM, Nicolas Peltier
<np...@adobe.com.invalid> wrote:
> org.osgi.service.cm.Configuration.update(dict) from sling pipes bundle does not trigger LoggerManagedServiceFactory.updated

How are you creating the config instance from ConfigurationAdmin
instance? You should use the listConfiguration approach [1] otherwise
the config instance would get "bound" to the calling bundle [2] which
would prevent that config from getting used by the Commons Log bundle


Chetan Mehrotra
[1] https://github.com/apache/sling/blob/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java#L191
[2] https://osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html#getConfiguration(java.lang.String)