Jump to content

Referencing log from a static context help


HeyImJamie

Recommended Posts

Probably being retarded here but I've been testing accessing a MySQL database and using System.out to check for errors - got it to work fine but since moving it over to osbot I've been trying to use the logger but can't access it 

 

Is there a way to use it outside onLoop etc or is there a way I've completely missed to use System.out.println?

Edited by HeyImJamie
Link to comment
Share on other sites

9 minutes ago, HeyImJamie said:

That's what I'm struggling with. My voids are static and I can't access log 

 

5 minutes ago, nosepicker said:

Pass in your main class to the method as a prameter where you want to use System.out then. Then do ParamName.log();

 

That or run OSBot in debug mode with the -debug flag, you can then see your printlns in CMD (or terminal)

  • Like 3
Link to comment
Share on other sites

38 minutes ago, HeyImJamie said:

Probably being retarded here but I've been testing accessing a MySQL database and using System.out to check for errors - got it to work fine but since moving it over to osbot I've been trying to use the logger but can't access it 

 

Is there a way to use it outside onLoop etc or is there a way I've completely missed to use System.out.println?

public class Logger {

     private static MethodProvider m;

     private Logger() {

     }

     public static void setup(MethodProvider m) {

          Logger.m = m;

     }

     public static void log(String message) {

          if(m != null)

                m.log(message);

     }     

}

 

this is a pretty basic way of doing it. just call setup in your onStart() and you should be able to use this. if you want a staticly accessible version of m just create a getter for m

Edited by Team Cape
Link to comment
Share on other sites

29 minutes ago, Team Cape said:

public class Logger {

     private static MethodProvider m;

     private Logger() {

     }

     public static void setup(MethodProvider m) {

          Logger.m = m;

     }

     public static void log(String message) {

          if(m != null)

                m.log(message);

     }     

}

 

this is a pretty basic way of doing it. just call setup in your onStart() and you should be able to use this. if you want a staticly accessible version of m just create a getter for m

 

Logger logger = new Logger();

 

logger.m = m;

 

edit: im thinkin more singleton but urs is fine ;)

Edited by dreameo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...