You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inside the phone storage, I've created a folder named "MyLogs". Within that folder, there are four subfolders. I'm trying to insert values into specific folders, not all of them.
private void initializeXLog() {
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// Get the downloads directory
// Create a File object representing the "GA Logs" directory within the downloads directory
File gaLogsDir = new File(downloadsDir, "LogsDemo");
// Get the current date in the format "dd_MMM" (e.g., "11_Apr")
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MMM");
String currentDate = dateFormat.format(new Date());
Date d = new Date();
SimpleDateFormat ff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = ff.format(d);
Log.i("Current Date and Time: ","Date1: " + formattedDate);
// Create a File object representing the current date folder within the "MyLogs" directory
File dateFolder = new File(gaLogsDir, currentDate);
// Create the "MyLogs" directory if it doesn't exist
if (!downloadsDir.exists()) {
downloadsDir.mkdirs(); // Make directories recursively
}
// Create the date folder if it doesn't exist
if (!dateFolder.exists()) {
dateFolder.mkdirs(); // Make directories recursively
}
// Initialize XLog with file printer
LogConfiguration config = new LogConfiguration.Builder()
.tag("MyApp")
.build();
// Create subfolders 'General', 'Sync', 'Mission', 'Task' inside the date folder
String[] subfolders = {"General",
"Sync",
"Mission",
"Task",
"LiveData",
"Vehicle Alerts"};
for (String subfolderName : subfolders) {
File subfolder = new File(dateFolder, subfolderName);
if (!subfolder.exists()) {
subfolder.mkdirs(); // Make directories recursively
}
FilePrinter filePrinter = new FilePrinter
.Builder(subfolder.getAbsolutePath())
.fileNameGenerator(new ChangelessFileNameGenerator("Indent_id_"))
.backupStrategy(new AbstractBackupStrategy() {
@Override
public int getMaxBackupIndex() {
return 0;
}
@Override
public boolean shouldBackup(File file) {
return file.length() > maxSize; // Backup if file size exceeds 1MB
}
@Override
public String getBackupFileName(String fileName, int backupIndex) {
return fileName + "_" + backupIndex;
}
})
.flattener(new ClassicFlattener())
.writer(new SimpleWriter() { // Default: SimpleWriter
@Override
public void onNewFileCreated(File file) {
super.onNewFileCreated(file);
final String header = "\n>>>>>>>>>>>>>>>> File Header >>>>>>>>>>>>>>>>" +
"\nDevice Manufacturer: " + Build.MANUFACTURER +
"\nDevice Model : " + Build.MODEL +
"\nAndroid Version : " + Build.VERSION.RELEASE +
"\nAndroid SDK : " + Build.VERSION.SDK_INT +
"\nApp VersionName : " + BuildConfig.VERSION_NAME +
"\nApp VersionCode : " + BuildConfig.VERSION_CODE +
"\n Date : "+ formattedDate+
"\n<<<<<<<<<<<<<<<< File Header <<<<<<<<<<<<<<<<\n\n";
appendLog(header);
}
})
.build();
XLog.init(config, new AndroidPrinter(), filePrinter);
}
isXLogInitialized = true;
}
I am calling the below method in some spefic acitivity acc to folder.
public void insertLog(String subfolderName, String message,String tag) {
// Check if XLog is initialized
if (!isXLogInitialized) {
Log.e("MyApplication", "XLog is not initialized. Call initializeXLog() first.");
return;
}
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// Get the downloads directory
// Create a File object representing the "GA Logs" directory within the downloads directory
File gaLogsDir = new File(downloadsDir, "LogsDemo");
// Get the current date in the format "dd_MMM" (e.g., "11_Apr")
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MMM");
String currentDate = dateFormat.format(new Date());
// Create a File object representing the current date folder within the "MyLogs" directory
File dateFolder = new File(gaLogsDir, currentDate);
// Create the subfolder if it doesn't exist
File subfolder = new File(dateFolder, subfolderName);
if (!subfolder.exists()) {
subfolder.mkdirs(); // Make directories recursively
}
// Insert log message into the specified subfolder
XLog.tag(tag).i(message);
}
when ever i putting values from GeneralAcitivity it is storing in vehicle folder.
button.setOnClickListener(v -> {
((XLogSampleApplication) getApplication()).insertLog("LogsDemo/General", "Btn Clicked","GeneralActivity");
});
I want as per specific folder
The text was updated successfully, but these errors were encountered:
Inside the phone storage, I've created a folder named "MyLogs". Within that folder, there are four subfolders. I'm trying to insert values into specific folders, not all of them.
private void initializeXLog() {
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// Get the downloads directory
// Create a File object representing the "GA Logs" directory within the downloads directory
File gaLogsDir = new File(downloadsDir, "LogsDemo");
public void insertLog(String subfolderName, String message,String tag) {
// Check if XLog is initialized
if (!isXLogInitialized) {
Log.e("MyApplication", "XLog is not initialized. Call initializeXLog() first.");
return;
}
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// Get the downloads directory
// Create a File object representing the "GA Logs" directory within the downloads directory
File gaLogsDir = new File(downloadsDir, "LogsDemo");
when ever i putting values from GeneralAcitivity it is storing in vehicle folder.
The text was updated successfully, but these errors were encountered: