Page 3 of 3
Re: Java compiler cannot find "write"
Posted: Wed Feb 15, 2023 1:07 pm
by seal58
Hi Terry,
you're right. I already use such liners to divide log blocks. That will do it for the moment too. I wanna finish my module first. May be that I'll continue working on the logger problem anytime.
Cheers
Roland
Re: Java compiler cannot find "write"
Posted: Wed Feb 15, 2023 5:02 pm
by UrbanCyborg
Roland, I've dug into things a bit more deeply. The properties for the loggers are under the control of a unique, system-level LogManager object, and apparently, any changes to log formatting have to go through it. The possibly easier route would be to create or modify the property file in <Java>\lib. My machine doesn't have one, so I couldn't check on the format; I only know that it's in something called LoggingProperties format. If you look up the object in the docs, it'll give you a hint (but not much more) on how to get a reference to the single LogManager object. At this point, we've exceeded my meager knowledge of Java.
A couple of points on the code I posted. First, ignore the copyright; since I posted it for anyone to use, it doesn't make any sense. It was auto-generated by my editor template for Java modules. Second, change the object path to refer to your own company, not Cyberwerks. And third, change the log file path to a location that makes sense for your usage.
I hope something here is useful to you.
Reid
Re: Java compiler cannot find "write"
Posted: Thu Feb 16, 2023 11:37 am
by seal58
Hi Reid,
I had a look at the files in Java lib folder. There I found just on
properties file, which is related to character sets only.
In Java docs there is not any keyword
LoggingProperties. But from class
Logger I came to class
LogManager and then to class
Properties. That mass of information starts to get me fully confused.
Two things I believe to understand:
- Format of logged messages can be modified on several system levels. Basically there is a default. It can be overridden by logger classes, that are extended from
Logger class and from specific logger handlers. In
LogManager class there is a
readConfiguration() method . That might could be used to configure log records. There's a lot of explanations with "but if ..., but if ... ". That exceeds my understanding at my actual Java beginner's level.
- Class
Properties deals with configuration data basically, where pairs of strings are used for each parameter, one for parameter's name and the other for it's value. (therefore XML file format is usable too) As I remember, in another topic Terry mentioned to use "property save / load methods" in order to store extra information. And that is, what I'm actually working on to save module data within
GetStateInformation(). But
Properties might also be usable to write simple logs for testing purposes into a log file.
No I'm working on my rather simple module for two months day after day. And from one thing I get to next one and seem not getting forward. But you might have similiar problem, where I am the reason.
I appreciate your patience very much. So once more thank you for taking your time and offering your logger tool.
Roland
Re: Java compiler cannot find "write"
Posted: Thu Feb 16, 2023 4:55 pm
by poetix
seal58 wrote: ↑Mon Feb 13, 2023 3:47 pm
Java compiler tells me "cannot find symbol 'format' ", though he should. "format" is a property of SimpleFormatter. I tryed adding an import statement of various variants whithout getting it compiled.
Do you have any idea what I did wrong?
The example from the Javadocs is of a line in a file setting configuration properties of the logging system - it isn't a line of Java code, although it may look like one. The Java code to set a property on something will usually look something like "formatter.setFormat(...)", because fields of classes are usually hidden away behind "setter" methods and not accessible directly. (This is purely by convention, and you can write your own classes any way you like).
I think it's unlikely you're going to be able to tunnel upstream into the VM environment to change the behaviour of its logger. You're in a sandbox, you get certain things handed to you to play with (in this case via methods exposed on the VoltageModule object your module inherits from), and for the most part you don't get to see, much less tamper with, whatever's behind the curtain.
Running this in debug mode
Code: Select all
import java.util.logging.LogManager;
...
@Override
public void Initialize()
{
// add your own code here
var e = LogManager.getLogManager().getLoggerNames();
while (e.hasMoreElements()) {
var s = e.nextElement();
Log("Logger: " + s);
}
}
I observed that there is a logger called "global". You can get hold of it and try to set its log level, like so:
Code: Select all
LogManager.getLogManager().getLogger("global").setLevel(java.util.logging.Level.INFO);
I suspect this is just the same as doing
Code: Select all
Logger.getGlobal().setLevel(java.util.logging.Level.INFO);
Whether that will actually affect the output of calling Log I don't know. There isn't an obvious way to reconfigure the formatting of the logger or anything like that; and nor should there be, since a client of the logging system shouldn't really be able to modify its behaviour in a way that would affect other clients (although I don't know how thoroughly sandboxed a VM module actually is - there must be at least classloader-level separation from other modules or you'd get horrible clashes between different version of imported libraries, etc).
Re: Java compiler cannot find "write"
Posted: Thu Feb 16, 2023 8:34 pm
by seal58
Hi poetix,
your doubts in changing system defaults by any user are realizable. I also realized, that there are lots of things more importand than an unwanted date line in a log file. Additionally I'm just sticking in other Java problems, that I have to focus at first.
Thanks for coming back with your explanations. If I have further clear questions, I will surely ask this forum, at least because here are some really Java high level skilled people as you are.
Roland