Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:37:31+00:00 2026-05-31T11:37:31+00:00

I want to implement OSGI bundle which can write error messages into log file.

  • 0

I want to implement OSGI bundle which can write error messages into log file. I have some some errors in the code that I cannot solve. I have commented the code code where Netbeans give me errors.

public class LoggingSystemImpl implements LoggingSystem {

   private final static Calendar calendar = Calendar.getInstance();
   private final static String user = System.getenv("USERNAME").toLowerCase();
   private final static String sMonth = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH);
   private final static int y = calendar.get(Calendar.YEAR);

   // the name of the log file
   //private final String logName = sysDrive + "\\fttb_web - " + sMonth.toLowerCase() + ", " + y + ".log";
   private final String logName = "logger - " + sMonth.toLowerCase() + ", " + y + ".log";

   private static boolean closed;
   private static Log log = null;
   private static BufferedWriter bw = null;
   private static FileOutputStream fos = null;
   private static OutputStreamWriter osw = null;

   public LoggingSystemImpl() {
   }


   public String LoggingSystemUtilization() throws FileNotFoundException{


       return "ok";
   }


   private String Log() throws IOException
{
    fos = new FileOutputStream(logName, true);

    // set encoding to cyrillic (if available)
    if (Charset.isSupported("windows-1251"))
    {
        osw = new OutputStreamWriter(fos, Charset.forName("windows-1251"));
    }
    else { osw = new OutputStreamWriter(fos); }

    bw = new BufferedWriter(osw, 2048); // 2Mb buffer

    return"ok";

}

// intro header for log session
public static synchronized Log getInstance() throws IOException
{
    boolean exc = false;
    try
    {
        if (log == null || closed)
        {
            log = new Log() {};

error message in Netbeans: is not abstract and does not override abstract method getPrintStream() in sun.rmi.runtime.Log

            closed = false;
            log.writeln("logged in.");

error message: cannot find symbol
symbol: method writeln(java.lang.String)
location: variable log of type sun.rmi.runtime.Log

log.nl();

error message: cannot find symbol
symbol: method nl()
location: variable log of type sun.rmi.runtime.Log

            }
        }
        catch(IOException x) { exc = true; throw x; }
        catch(Exception x) { exc = true; x.printStackTrace(); }
        finally
        {
            if (exc)
            {
                try
                {
                    if (fos != null) { fos.close(); fos = null; }
                    if (osw != null) { osw.close(); fos = null; }
                    if (bw != null)  { bw.close(); bw = null; }
                }
                catch(Exception x) { x.printStackTrace(); }
            }
        }
        return log;
    }


    public synchronized void nl()
    {
        try { bw.newLine(); }
        catch(IOException x) {x.printStackTrace();}
    }

    public synchronized void nl(int count)
    {
        try
        {
            for (int i = 0; i < count; i++) bw.newLine();
        }
        catch(IOException x) {x.printStackTrace();}
    }
    public synchronized void writeln(String s)
    {
        try { bw.write(getTime() + ": " + s); bw.newLine(); }
        catch(IOException x) {x.printStackTrace();}
    }

    public synchronized void write(String s)
    {
        try { bw.write(s); }
        catch (IOException x) {x.printStackTrace();}
    }

    public synchronized void close()
    {
        try
        {
            if (bw != null)
            {
                writeln("logged out.");
                nl();
                bw.flush();
                bw.close();
                closed = true;

                fos = null;
                osw = null;
                bw = null;
            }
        }
        catch(IOException x) { x.printStackTrace(); }

    }

    public synchronized boolean isClosed() { return closed; }

    public synchronized void writeException(Exception x)
    {
        writeln("");
        write("\t" + x.toString()); nl();
        StackTraceElement[] ste = x.getStackTrace();
        int j = 0;
        for (int i = 0; i < ste.length; i++)
        {

            if (i < 15) { write("\t\tat " + ste[i].toString()); nl(); }
            else { j++; }

        }

        if (j > 0) { write("\t\t... " + j + " more"); nl(); }

        nl(2);
    }

    private String getTime()
    {
        Calendar c = Calendar.getInstance();
        int month = c.get(Calendar.MONTH) + 1;

        int d = c.get(Calendar.DAY_OF_MONTH);
        int h = c.get(Calendar.HOUR_OF_DAY);

        int m = c.get(Calendar.MINUTE);
        int s = c.get(Calendar.SECOND);
        int y = c.get(Calendar.YEAR);

        String dd = d < 10 ? "0"+d : ""+d;
        String hh = h < 10 ? "0"+h : ""+h;
        String mm = m < 10 ? "0"+m : ""+m;
        String ss = s < 10 ? "0"+s : ""+s;
        String sm = month < 10 ? "0"+month : ""+month;

        return user + " [" + y + "." + sm + "." + dd + " " + hh +  ":" + mm +  ":" + ss + "]";
    }





}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:37:32+00:00Added an answer on May 31, 2026 at 11:37 am

    I’m almost certain you are using the wrong Log class. Anything in sun.* packages is not for user consumption.
    If you want logging for your code, use the java.util.logging library or log4j. Or maybe OSGI provides a framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop logging system in OSGI bundle which can write application errors
I want to implement a simple debug log, which consists of a table into
I want to implement some action when CTRL-A is pressed . How can I
i have question for example i want to implement binary tree with array i
I want implement a program that can do a a Vision-based Page Segmentation. I
Can any one help me to give some hint about How can i implement
I want to implement carriage return within xslt. The problem is I have a
I'm trying to build a maven project, an OSGi bundle, which contains Webservices. I'm
I need add paging to panel, which populated with dynamically-created controls. I want implement
I want to implement UITableView Where I want to have 3 buttons in each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.