LoggerFactory cannot getLogger
I'm currently implementing a Logger and I'm wondering why the code won't run.
Most of the codes snipets are like these:
Logger log = LoggerFactory.getLogger(this.getClass());
My imported classes:
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogReaderService;
import org.osgi.service.log.LogService;
import org.osgi.service.log.Logger;
import org.osgi.service.log.LoggerFactory;
But I can't seem to use getLogger.
Why is that?
Thanks in advance!
java eclipse logging osgi loggerfactory
|
show 2 more comments
I'm currently implementing a Logger and I'm wondering why the code won't run.
Most of the codes snipets are like these:
Logger log = LoggerFactory.getLogger(this.getClass());
My imported classes:
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogReaderService;
import org.osgi.service.log.LogService;
import org.osgi.service.log.Logger;
import org.osgi.service.log.LoggerFactory;
But I can't seem to use getLogger.
Why is that?
Thanks in advance!
java eclipse logging osgi loggerfactory
Instead of images, please provide the relevant part of your code. Add a Minimal, Complete, and Verifiable example including proper example input/output data.
– Bsquare ℬℬ
Nov 21 '18 at 9:25
I'm wondering what i'm doing wrong because it doesn't display the getLogger methods
– Mel Sy Gallosa
Nov 21 '18 at 9:33
Can you post the import section of that class?
– user10639668
Nov 21 '18 at 9:34
@EugenCovaci I edited the post. :)
– Mel Sy Gallosa
Nov 21 '18 at 9:38
If you writeLogger log = LoggerFactory.getLogger(this.getClass());
directly, do you get a compiler error?
– user10639668
Nov 21 '18 at 9:43
|
show 2 more comments
I'm currently implementing a Logger and I'm wondering why the code won't run.
Most of the codes snipets are like these:
Logger log = LoggerFactory.getLogger(this.getClass());
My imported classes:
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogReaderService;
import org.osgi.service.log.LogService;
import org.osgi.service.log.Logger;
import org.osgi.service.log.LoggerFactory;
But I can't seem to use getLogger.
Why is that?
Thanks in advance!
java eclipse logging osgi loggerfactory
I'm currently implementing a Logger and I'm wondering why the code won't run.
Most of the codes snipets are like these:
Logger log = LoggerFactory.getLogger(this.getClass());
My imported classes:
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogReaderService;
import org.osgi.service.log.LogService;
import org.osgi.service.log.Logger;
import org.osgi.service.log.LoggerFactory;
But I can't seem to use getLogger.
Why is that?
Thanks in advance!
java eclipse logging osgi loggerfactory
java eclipse logging osgi loggerfactory
edited Nov 21 '18 at 9:38
Mel Sy Gallosa
asked Nov 21 '18 at 9:18
Mel Sy GallosaMel Sy Gallosa
1942618
1942618
Instead of images, please provide the relevant part of your code. Add a Minimal, Complete, and Verifiable example including proper example input/output data.
– Bsquare ℬℬ
Nov 21 '18 at 9:25
I'm wondering what i'm doing wrong because it doesn't display the getLogger methods
– Mel Sy Gallosa
Nov 21 '18 at 9:33
Can you post the import section of that class?
– user10639668
Nov 21 '18 at 9:34
@EugenCovaci I edited the post. :)
– Mel Sy Gallosa
Nov 21 '18 at 9:38
If you writeLogger log = LoggerFactory.getLogger(this.getClass());
directly, do you get a compiler error?
– user10639668
Nov 21 '18 at 9:43
|
show 2 more comments
Instead of images, please provide the relevant part of your code. Add a Minimal, Complete, and Verifiable example including proper example input/output data.
– Bsquare ℬℬ
Nov 21 '18 at 9:25
I'm wondering what i'm doing wrong because it doesn't display the getLogger methods
– Mel Sy Gallosa
Nov 21 '18 at 9:33
Can you post the import section of that class?
– user10639668
Nov 21 '18 at 9:34
@EugenCovaci I edited the post. :)
– Mel Sy Gallosa
Nov 21 '18 at 9:38
If you writeLogger log = LoggerFactory.getLogger(this.getClass());
directly, do you get a compiler error?
– user10639668
Nov 21 '18 at 9:43
Instead of images, please provide the relevant part of your code. Add a Minimal, Complete, and Verifiable example including proper example input/output data.
– Bsquare ℬℬ
Nov 21 '18 at 9:25
Instead of images, please provide the relevant part of your code. Add a Minimal, Complete, and Verifiable example including proper example input/output data.
– Bsquare ℬℬ
Nov 21 '18 at 9:25
I'm wondering what i'm doing wrong because it doesn't display the getLogger methods
– Mel Sy Gallosa
Nov 21 '18 at 9:33
I'm wondering what i'm doing wrong because it doesn't display the getLogger methods
– Mel Sy Gallosa
Nov 21 '18 at 9:33
Can you post the import section of that class?
– user10639668
Nov 21 '18 at 9:34
Can you post the import section of that class?
– user10639668
Nov 21 '18 at 9:34
@EugenCovaci I edited the post. :)
– Mel Sy Gallosa
Nov 21 '18 at 9:38
@EugenCovaci I edited the post. :)
– Mel Sy Gallosa
Nov 21 '18 at 9:38
If you write
Logger log = LoggerFactory.getLogger(this.getClass());
directly, do you get a compiler error?– user10639668
Nov 21 '18 at 9:43
If you write
Logger log = LoggerFactory.getLogger(this.getClass());
directly, do you get a compiler error?– user10639668
Nov 21 '18 at 9:43
|
show 2 more comments
2 Answers
2
active
oldest
votes
Here is the source code of org.osgi.service.log.LoggerFactory
.
As you can see, it's an interface with no static methods therefore this code:
Logger log = LoggerFactory.getLogger(this.getClass());
is simply not valid.
To fix this use slf4j
as front end (this means replace org.osgi.service.log.LoggerFactory
import with org.slf4j.LoggerFactory
etc.).
UPDATE
If you want to stick with org.osgi.service.log.LoggerFactory
then follow this:
Obtain the LoggerFactory instance:
public class Activator implements BundleActivator
{
private volatile LoggerFactory loggerFactory;
public void start(BundleContext context) throws Exception
{
ServiceReference ref = context.getServiceReference(LoggerFactory.class.getName());
if (ref != null)
{
loggerFactory = (LoggerFactory) context.getService(ref);
}
}
//..
Elsewhere in the bundle you can then use the LoggerFactory to get a Logger for any class:
Logger logger = loggerFactory.getLogger(Foo.class);
UPDATE2
A better alternative would be to get a reference who's service type is LoggerFactory like this:
@Reference(service = LoggerFactory.class)
private Logger logger;
But I need to use this LoggerFactory/Logger to change from LogService (since LogService has been depreciated in 1.4) Please help. Thanks!
– Mel Sy Gallosa
Nov 21 '18 at 9:56
But I'll try using this. I hope it works.
– Mel Sy Gallosa
Nov 21 '18 at 10:00
Oh. I need to use plugins from eclipse only >_<
– Mel Sy Gallosa
Nov 21 '18 at 10:04
@MelSyGallosa See my updated answer
– user10639668
Nov 21 '18 at 10:06
1
@NeilBartlett Done.
– user10639668
Nov 22 '18 at 15:41
|
show 8 more comments
LoggerFactory is an OSGi service. You need to get it from the OSGi service registry. See my EclipseCon Europe 2018 presentation for more information.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408718%2floggerfactory-cannot-getlogger%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is the source code of org.osgi.service.log.LoggerFactory
.
As you can see, it's an interface with no static methods therefore this code:
Logger log = LoggerFactory.getLogger(this.getClass());
is simply not valid.
To fix this use slf4j
as front end (this means replace org.osgi.service.log.LoggerFactory
import with org.slf4j.LoggerFactory
etc.).
UPDATE
If you want to stick with org.osgi.service.log.LoggerFactory
then follow this:
Obtain the LoggerFactory instance:
public class Activator implements BundleActivator
{
private volatile LoggerFactory loggerFactory;
public void start(BundleContext context) throws Exception
{
ServiceReference ref = context.getServiceReference(LoggerFactory.class.getName());
if (ref != null)
{
loggerFactory = (LoggerFactory) context.getService(ref);
}
}
//..
Elsewhere in the bundle you can then use the LoggerFactory to get a Logger for any class:
Logger logger = loggerFactory.getLogger(Foo.class);
UPDATE2
A better alternative would be to get a reference who's service type is LoggerFactory like this:
@Reference(service = LoggerFactory.class)
private Logger logger;
But I need to use this LoggerFactory/Logger to change from LogService (since LogService has been depreciated in 1.4) Please help. Thanks!
– Mel Sy Gallosa
Nov 21 '18 at 9:56
But I'll try using this. I hope it works.
– Mel Sy Gallosa
Nov 21 '18 at 10:00
Oh. I need to use plugins from eclipse only >_<
– Mel Sy Gallosa
Nov 21 '18 at 10:04
@MelSyGallosa See my updated answer
– user10639668
Nov 21 '18 at 10:06
1
@NeilBartlett Done.
– user10639668
Nov 22 '18 at 15:41
|
show 8 more comments
Here is the source code of org.osgi.service.log.LoggerFactory
.
As you can see, it's an interface with no static methods therefore this code:
Logger log = LoggerFactory.getLogger(this.getClass());
is simply not valid.
To fix this use slf4j
as front end (this means replace org.osgi.service.log.LoggerFactory
import with org.slf4j.LoggerFactory
etc.).
UPDATE
If you want to stick with org.osgi.service.log.LoggerFactory
then follow this:
Obtain the LoggerFactory instance:
public class Activator implements BundleActivator
{
private volatile LoggerFactory loggerFactory;
public void start(BundleContext context) throws Exception
{
ServiceReference ref = context.getServiceReference(LoggerFactory.class.getName());
if (ref != null)
{
loggerFactory = (LoggerFactory) context.getService(ref);
}
}
//..
Elsewhere in the bundle you can then use the LoggerFactory to get a Logger for any class:
Logger logger = loggerFactory.getLogger(Foo.class);
UPDATE2
A better alternative would be to get a reference who's service type is LoggerFactory like this:
@Reference(service = LoggerFactory.class)
private Logger logger;
But I need to use this LoggerFactory/Logger to change from LogService (since LogService has been depreciated in 1.4) Please help. Thanks!
– Mel Sy Gallosa
Nov 21 '18 at 9:56
But I'll try using this. I hope it works.
– Mel Sy Gallosa
Nov 21 '18 at 10:00
Oh. I need to use plugins from eclipse only >_<
– Mel Sy Gallosa
Nov 21 '18 at 10:04
@MelSyGallosa See my updated answer
– user10639668
Nov 21 '18 at 10:06
1
@NeilBartlett Done.
– user10639668
Nov 22 '18 at 15:41
|
show 8 more comments
Here is the source code of org.osgi.service.log.LoggerFactory
.
As you can see, it's an interface with no static methods therefore this code:
Logger log = LoggerFactory.getLogger(this.getClass());
is simply not valid.
To fix this use slf4j
as front end (this means replace org.osgi.service.log.LoggerFactory
import with org.slf4j.LoggerFactory
etc.).
UPDATE
If you want to stick with org.osgi.service.log.LoggerFactory
then follow this:
Obtain the LoggerFactory instance:
public class Activator implements BundleActivator
{
private volatile LoggerFactory loggerFactory;
public void start(BundleContext context) throws Exception
{
ServiceReference ref = context.getServiceReference(LoggerFactory.class.getName());
if (ref != null)
{
loggerFactory = (LoggerFactory) context.getService(ref);
}
}
//..
Elsewhere in the bundle you can then use the LoggerFactory to get a Logger for any class:
Logger logger = loggerFactory.getLogger(Foo.class);
UPDATE2
A better alternative would be to get a reference who's service type is LoggerFactory like this:
@Reference(service = LoggerFactory.class)
private Logger logger;
Here is the source code of org.osgi.service.log.LoggerFactory
.
As you can see, it's an interface with no static methods therefore this code:
Logger log = LoggerFactory.getLogger(this.getClass());
is simply not valid.
To fix this use slf4j
as front end (this means replace org.osgi.service.log.LoggerFactory
import with org.slf4j.LoggerFactory
etc.).
UPDATE
If you want to stick with org.osgi.service.log.LoggerFactory
then follow this:
Obtain the LoggerFactory instance:
public class Activator implements BundleActivator
{
private volatile LoggerFactory loggerFactory;
public void start(BundleContext context) throws Exception
{
ServiceReference ref = context.getServiceReference(LoggerFactory.class.getName());
if (ref != null)
{
loggerFactory = (LoggerFactory) context.getService(ref);
}
}
//..
Elsewhere in the bundle you can then use the LoggerFactory to get a Logger for any class:
Logger logger = loggerFactory.getLogger(Foo.class);
UPDATE2
A better alternative would be to get a reference who's service type is LoggerFactory like this:
@Reference(service = LoggerFactory.class)
private Logger logger;
edited Nov 22 '18 at 15:41
answered Nov 21 '18 at 9:49
user10639668
But I need to use this LoggerFactory/Logger to change from LogService (since LogService has been depreciated in 1.4) Please help. Thanks!
– Mel Sy Gallosa
Nov 21 '18 at 9:56
But I'll try using this. I hope it works.
– Mel Sy Gallosa
Nov 21 '18 at 10:00
Oh. I need to use plugins from eclipse only >_<
– Mel Sy Gallosa
Nov 21 '18 at 10:04
@MelSyGallosa See my updated answer
– user10639668
Nov 21 '18 at 10:06
1
@NeilBartlett Done.
– user10639668
Nov 22 '18 at 15:41
|
show 8 more comments
But I need to use this LoggerFactory/Logger to change from LogService (since LogService has been depreciated in 1.4) Please help. Thanks!
– Mel Sy Gallosa
Nov 21 '18 at 9:56
But I'll try using this. I hope it works.
– Mel Sy Gallosa
Nov 21 '18 at 10:00
Oh. I need to use plugins from eclipse only >_<
– Mel Sy Gallosa
Nov 21 '18 at 10:04
@MelSyGallosa See my updated answer
– user10639668
Nov 21 '18 at 10:06
1
@NeilBartlett Done.
– user10639668
Nov 22 '18 at 15:41
But I need to use this LoggerFactory/Logger to change from LogService (since LogService has been depreciated in 1.4) Please help. Thanks!
– Mel Sy Gallosa
Nov 21 '18 at 9:56
But I need to use this LoggerFactory/Logger to change from LogService (since LogService has been depreciated in 1.4) Please help. Thanks!
– Mel Sy Gallosa
Nov 21 '18 at 9:56
But I'll try using this. I hope it works.
– Mel Sy Gallosa
Nov 21 '18 at 10:00
But I'll try using this. I hope it works.
– Mel Sy Gallosa
Nov 21 '18 at 10:00
Oh. I need to use plugins from eclipse only >_<
– Mel Sy Gallosa
Nov 21 '18 at 10:04
Oh. I need to use plugins from eclipse only >_<
– Mel Sy Gallosa
Nov 21 '18 at 10:04
@MelSyGallosa See my updated answer
– user10639668
Nov 21 '18 at 10:06
@MelSyGallosa See my updated answer
– user10639668
Nov 21 '18 at 10:06
1
1
@NeilBartlett Done.
– user10639668
Nov 22 '18 at 15:41
@NeilBartlett Done.
– user10639668
Nov 22 '18 at 15:41
|
show 8 more comments
LoggerFactory is an OSGi service. You need to get it from the OSGi service registry. See my EclipseCon Europe 2018 presentation for more information.
add a comment |
LoggerFactory is an OSGi service. You need to get it from the OSGi service registry. See my EclipseCon Europe 2018 presentation for more information.
add a comment |
LoggerFactory is an OSGi service. You need to get it from the OSGi service registry. See my EclipseCon Europe 2018 presentation for more information.
LoggerFactory is an OSGi service. You need to get it from the OSGi service registry. See my EclipseCon Europe 2018 presentation for more information.
answered Nov 21 '18 at 14:21
BJ HargraveBJ Hargrave
8,10111425
8,10111425
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408718%2floggerfactory-cannot-getlogger%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Instead of images, please provide the relevant part of your code. Add a Minimal, Complete, and Verifiable example including proper example input/output data.
– Bsquare ℬℬ
Nov 21 '18 at 9:25
I'm wondering what i'm doing wrong because it doesn't display the getLogger methods
– Mel Sy Gallosa
Nov 21 '18 at 9:33
Can you post the import section of that class?
– user10639668
Nov 21 '18 at 9:34
@EugenCovaci I edited the post. :)
– Mel Sy Gallosa
Nov 21 '18 at 9:38
If you write
Logger log = LoggerFactory.getLogger(this.getClass());
directly, do you get a compiler error?– user10639668
Nov 21 '18 at 9:43