boost.log v2, how to get the current log file name - c++

I'm updating a C++ class wrapping the boost logger to use a recent boost version with the logger v2 API.
Most of the work have been done, but with the logger v1 we used an API to get the current log file name and path like in the example below:
boost::filesystem::path p = pAsyncFileSink->locked_backend()->get_log_filename()
I searched for some hour, but I don't find a way to do that with the current API ! if we use a rotating text file backend, how to get the latest or in use file name ?
Any help or advice will be welcome.
Alex.

There is no API to obtain the current file name. You can see in the implementation that the file name is generated only when file rotation is performed, making it possible for the sink to not have a file name in certain points in time.

Related

Save a downloaded file to storage folder on android

I've made an app that sends a file from my pc to my phone but I can't figure out how to save it to Internal storage or to a folder I can access. Can someone please help?
Looks like you need to use the FileSystem API. According to the documentation here, you need to first install it:
expo install expo-file-system
And of course, import it where needed:
import * as FileSystem from 'expo-file-system';
After which you should be able to use the method FileSystem.writeAsStringAsync and save the file to the FileSystem.documentDirectory:
FileSystem.writeAsStringAsync(
FileSystem.documentDirectory + 'filename.ext',
"some file contents or variable");
Look around the documentation about FileSystem - there are many useful methods and some examples that should help you.

Modify how a tf.estimator.Estimator creates summaries for Tensorboard

I'm trying to find out how I can modify the way a custom TensorFlow estimator creates event files for Tensorboard. Currently, I have the impression that, by default, a summary (containing the values of all the things (like typically accuracy) I'm following with tf.summary.scalar(...) ) is created every 100 steps in my model directory. The names of the event files later used by tensorboard look like
events.out.tfevents.1531418661.nameofmycomputer.
I found a routine online to change this behaviour and create directories for each run with the date and time of the computation, but it uses TensorFlow basic APIs:
logdir = "tensorboard/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + "/"
writer = tf.summary.FileWriter(logdir, sess.graph)
Is it possible to do something similar with a TF custom estimator?
It is possible to specify a directory for each evaluation run using name argument of the evaluate method of tf.estimator.Estimator e.g.:
estimator = tf.estimator.Estimator(
model_fn=model_fn,
model_dir=model_dir
)
eval_results = estimator.evaluate(
input_fn=eval_input_fn,
name=eval_name
)
The event files for this evaluation will be saved in the directory inside model_dir named "eval_" + eval_name.
Summary Writers are not needed for TensorFlow Estimators. The summary log of the model is written to the designated folder location using the model_dir attribute of tf.Estimator function when the tf.Estimator.fit() method is called.
In the example below, the selected directory to store the training logs is './my_model'.
tf.estimator.DNNClassifier(
model_fn,
model_dir='./my_model',
config=None,
params=None,
warm_start_from=None
)
Launch TensorBoard by running tensorboard --logdir=./my_model from the terminal.

Can log4j and java util logging coexist

My application uses log4j but OkHttpClient uses java util logging. So apart from log4j.properties, I created a logging.properties file with the following contents:
handlers=java.util.logging.FileHandler
.level=FINE
okhttp3.internal.http2.level=FINE
java.util.logging.FileHandler.pattern = logs/%hjava%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
I then added this to jvm params used for starting the application -Djava.util.logging.config.file="file://${BASE_DIR}/logging.properties"
But I don't see any new folders being created as indicated by the Filehandler. Any one know why?
But I don't see any new folders being created as indicated by the Filehandler. Any one know why?
The FileHandler will not create any new folders. A directory must be created before the FileHandler will create a file.
The system property requires a path to file that is located on the filesystem It will not expand system properties or environment variables by using the dollar sign syntax.
You can use a relative path based off of the working directory or you have to use an absolute path to the logging.properties. The logging properties can not be packaged inside of an archive.
If you want to work around this limitation then you want to create a custom config class and use the java.util.logging.config.class property in conjunction with the java.util.logging.config.file property. You then write a class that reads the file://${BASE_DIR}/logging.properties and performs the needed transformation into a path to a file. Then update the configuration if you are using JDK9 or newer. On older versions you need to use readConfiguration and add code to work work around limitations of the LogManager

Creating a pst file using Redemption

I'm working on a project in C# that involves parsing .pst files and my group has chosen to use the Redemption library to do so. We have successfully parsed the email files in to RDOMail objects, however now we want to write a subset of those emails to a new .pst file. I have successfully written the subset to .eml files using the email.SaveAs() function, but I'm at a loss to figure out how to save that list as a .pst. I've been sifting through the documentation, however it leaves much to be desired. Can anyone who has used Redemption point me in the right direction or provide an example?? Thanks in advance for your help!
You will need to create/open a PST file using RDOSession.Stores.AddPstStore (returns RDOPSTStore object). Once you have the store, you can open/create folders (starting with the RDOStore.IPMRootFolder), create messages (RDOFolder.Items.Add) and copy old messages into new messages (RDOMail.CopyTo(RDOMail/RDOFolder)).
I have been struggling to do this for the last few hours and would like to save that time to others
You have to install redemption and add it as a reference to your project for it to work
RDOSession session = new RDOSession(); // throws exception 1
session.LogonPstStore(#"c:\temp\output.pst");
RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
string[] fileEntries = Directory.GetFiles(#"C:\emlFiles\", "*.eml");
foreach (string filePath in fileEntries)
{
RDOMail mail = folder.Items.Add("IPM.Mail");
mail.Sent = true;
mail.Import(filePath, 1024);
// folder.Items.Add(mail);
mail.Save();
}
session.Logoff();
I also created a small sample windows forms app for it, I know the code is ugly but it does the trick

Reading a file from Java Servlet

I wrote some code to read a file in my Java Servlet class. (I'm using Netbeans on Windows along with Tomcat server). However, my servlet cannot find the file!
After much digging, I found that I had to place the file I wanted to read in Tomcat/bin folder. That's very surprising. How can I get the path to my Webapps/ folder? Let's assume my website project is called "Web1".
Essentially what I'm doing is I'm trying to read my .xsl file for converting my DOM Document to be an HTML. At first I tried placing this .xsl file everywhere (at the same level as my index.jsp, in the same directory as my servlet class file, etc...but didnt work at all)
Also, when I finished transform(), my HTML file also goes into the Tomcat/bin folder~!
Can you use javax.servlet.ServletContext.getRealPath(String path)?
Returns a String containing the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/index.html", where contextPath is the context path of this ServletContext..
The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).
Where are you consuming that XSL? If from your Java code place the file into src/java/resources so it will end up in the top of your classpath when the WAR is assembled /WEB-INF/classes/foo.xsl. Then you can use Class#getResource("foo.xsl") or even better if you are using DOM4J or equivalent there are ways of loading the file.
Now if it is you JavaScript that performs the transformation on the client that's a different story
Something like this might be more convenient for you:
java.net.URL url = ClassLoader.getSystemResource(file_name);
try {
InputStream is = url.openStream());
//Read the file and do stuff
} catch(IOException e) {
System.err.println("Error: could not load the file");
}
This will allow you to get an InputStream for a file within the classpath (in your case, something in the webapps folder). As for writing results, I'm not sure.