use of org.apache.geode.internal.logging.log4j.LogWriterAppender in project geode by apache.
the class MemberMBeanBridge method fetchLog.
/**
* @return log of the member.
*/
public String fetchLog(int numLines) {
if (numLines > ManagementConstants.MAX_SHOW_LOG_LINES) {
numLines = ManagementConstants.MAX_SHOW_LOG_LINES;
}
if (numLines == 0 || numLines < 0) {
numLines = ManagementConstants.DEFAULT_SHOW_LOG_LINES;
}
String childTail = null;
String mainTail = null;
try {
InternalDistributedSystem sys = system;
LogWriterAppender lwa = LogWriterAppenders.getAppender(LogWriterAppenders.Identifier.MAIN);
if (lwa != null) {
childTail = BeanUtilFuncs.tailSystemLog(lwa.getChildLogFile(), numLines);
mainTail = BeanUtilFuncs.tailSystemLog(sys.getConfig(), numLines);
if (mainTail == null) {
mainTail = LocalizedStrings.TailLogResponse_NO_LOG_FILE_WAS_SPECIFIED_IN_THE_CONFIGURATION_MESSAGES_WILL_BE_DIRECTED_TO_STDOUT.toLocalizedString();
}
} else {
Assert.assertTrue(false, "TailLogRequest/Response processed in application vm with shared logging.");
}
} catch (IOException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.TailLogResponse_ERROR_OCCURRED_WHILE_READING_SYSTEM_LOG__0, e));
mainTail = "";
}
if (childTail == null && mainTail == null) {
return LocalizedStrings.SystemMemberImpl_NO_LOG_FILE_CONFIGURED_LOG_MESSAGES_WILL_BE_DIRECTED_TO_STDOUT.toLocalizedString();
} else {
StringBuilder result = new StringBuilder();
if (mainTail != null) {
result.append(mainTail);
}
if (childTail != null) {
result.append(getLineSeparator()).append(LocalizedStrings.SystemMemberImpl_TAIL_OF_CHILD_LOG.toLocalizedString()).append(getLineSeparator());
result.append(childTail);
}
return result.toString();
}
}
use of org.apache.geode.internal.logging.log4j.LogWriterAppender in project geode by apache.
the class StatArchiveHandler method getRollingArchiveName.
/**
* Returns the modified archive file name to use after incrementing {@link #mainArchiveId} and
* {@link #archiveId} based on existing files {@link #archiveDir}. This is only used if
* {@link StatArchiveHandlerConfig#getArchiveFileSizeLimit() file size limit} has been specified
* as non-zero (which enables file rolling).
*
* @param archive the archive file name to modify
* @param archiveClosed true if archive was just being written by us; false if it was written by
* the previous process.
*
* @return the modified archive file name to use; it is modified by applying mainArchiveId and
* archiveId to the name for supporting file rolling
*/
File getRollingArchiveName(File archive, boolean archiveClosed) {
if (mainArchiveId != -1) {
// leave mainArchiveId as is. Bump archiveId.
} else {
archiveDir = archive.getAbsoluteFile().getParentFile();
LogWriterAppender lwa = LogWriterAppenders.getAppender(LogWriterAppenders.Identifier.MAIN);
boolean mainArchiveIdCalculated = false;
if (lwa != null) {
File logDir = lwa.getLogDir();
if (archiveDir.equals(logDir)) {
mainArchiveId = lwa.getMainLogId();
if (mainArchiveId > 1 && lwa.useChildLogging()) {
mainArchiveId--;
}
mainArchiveIdCalculated = true;
}
}
if (!mainArchiveIdCalculated) {
if (!archiveDir.exists()) {
archiveDir.mkdirs();
}
mainArchiveId = this.rollingFileHandler.calcNextMainId(archiveDir, false);
mainArchiveIdCalculated = true;
}
if (mainArchiveId == 0) {
mainArchiveId = 1;
}
archiveId = this.rollingFileHandler.calcNextChildId(archive, mainArchiveId);
if (archiveId > 0) {
archiveId--;
}
}
File result = null;
do {
archiveId++;
StringBuffer buf = new StringBuffer(archive.getPath());
int insertIdx = buf.lastIndexOf(".");
if (insertIdx == -1) {
buf.append(this.rollingFileHandler.formatId(mainArchiveId)).append(this.rollingFileHandler.formatId(archiveId));
} else {
buf.insert(insertIdx, this.rollingFileHandler.formatId(archiveId));
buf.insert(insertIdx, this.rollingFileHandler.formatId(mainArchiveId));
}
result = new File(buf.toString());
} while (result.exists());
if (archiveId == 1) {
// see if a marker file exists. If so delete it.
String markerName = archive.getPath();
int dotIdx = markerName.lastIndexOf(".");
if (dotIdx != -1) {
// strip the extension off
markerName = markerName.substring(0, dotIdx);
}
StringBuffer buf = new StringBuffer(markerName);
buf.append(this.rollingFileHandler.formatId(mainArchiveId)).append(this.rollingFileHandler.formatId(0)).append(".marker");
File marker = new File(buf.toString());
if (marker.exists()) {
if (!marker.delete()) {
// could not delete it; nothing to be done
}
}
}
if (!archiveClosed) {
mainArchiveId++;
archiveId = 0;
// create an empty file which we can use on startup when we don't roll
// to correctly rename the old archive that did not roll.
String markerName = archive.getPath();
int dotIdx = markerName.lastIndexOf(".");
if (dotIdx != -1) {
// strip the extension off
markerName = markerName.substring(0, dotIdx);
}
StringBuffer buf = new StringBuffer(markerName);
buf.append(this.rollingFileHandler.formatId(mainArchiveId)).append(this.rollingFileHandler.formatId(0)).append(".marker");
File marker = new File(buf.toString());
if (!marker.exists()) {
try {
if (!marker.createNewFile()) {
// could not create it; that is ok
}
} catch (IOException ignore) {
// If we can't create the marker that is ok
}
}
}
return result;
}
use of org.apache.geode.internal.logging.log4j.LogWriterAppender in project geode by apache.
the class StatArchiveHandler method initMainArchiveId.
void initMainArchiveId(File archive) {
if (mainArchiveId != -1) {
// already initialized
return;
}
archiveDir = archive.getAbsoluteFile().getParentFile();
LogWriterAppender lwa = LogWriterAppenders.getAppender(LogWriterAppenders.Identifier.MAIN);
boolean mainArchiveIdCalculated = false;
if (lwa != null) {
File logDir = lwa.getLogDir();
if (archiveDir.equals(logDir)) {
mainArchiveId = lwa.getMainLogId();
mainArchiveIdCalculated = true;
}
}
if (!mainArchiveIdCalculated) {
if (!archiveDir.exists()) {
archiveDir.mkdirs();
}
mainArchiveId = this.rollingFileHandler.calcNextMainId(archiveDir, false);
mainArchiveId++;
mainArchiveIdCalculated = true;
}
if (mainArchiveId == 0) {
mainArchiveId = 1;
}
archiveId = 0;
// create an empty file which we can use on startup when we don't roll
// to correctly rename the old archive that did not roll.
String markerName = archive.getPath();
int dotIdx = markerName.lastIndexOf(".");
if (dotIdx != -1) {
// strip the extension off
markerName = markerName.substring(0, dotIdx);
}
StringBuffer buf = new StringBuffer(markerName);
buf.append(this.rollingFileHandler.formatId(mainArchiveId)).append(this.rollingFileHandler.formatId(0)).append(".marker");
File marker = new File(buf.toString());
if (!marker.exists()) {
try {
if (!marker.createNewFile()) {
// could not create it; that is ok
}
} catch (IOException ignore) {
// If we can't create the marker that is ok
}
}
}
use of org.apache.geode.internal.logging.log4j.LogWriterAppender in project geode by apache.
the class TailLogResponse method create.
public static TailLogResponse create(DistributionManager dm, InternalDistributedMember recipient) {
TailLogResponse m = new TailLogResponse();
m.setRecipient(recipient);
try {
InternalDistributedSystem sys = dm.getSystem();
LogWriterAppender lwa = LogWriterAppenders.getAppender(LogWriterAppenders.Identifier.MAIN);
if (lwa != null) {
m.childTail = tailSystemLog(lwa.getChildLogFile());
m.tail = tailSystemLog(sys.getConfig());
if (m.tail == null) {
m.tail = LocalizedStrings.TailLogResponse_NO_LOG_FILE_WAS_SPECIFIED_IN_THE_CONFIGURATION_MESSAGES_WILL_BE_DIRECTED_TO_STDOUT.toLocalizedString();
}
} else {
// Assert.assertTrue(false, "TailLogRequest/Response processed in application vm with shared
// logging.");
m.childTail = tailSystemLog((File) null);
m.tail = tailSystemLog(sys.getConfig());
if (m.tail == null) {
m.tail = LocalizedStrings.TailLogResponse_NO_LOG_FILE_WAS_SPECIFIED_IN_THE_CONFIGURATION_MESSAGES_WILL_BE_DIRECTED_TO_STDOUT.toLocalizedString();
}
}
} catch (IOException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.TailLogResponse_ERROR_OCCURRED_WHILE_READING_SYSTEM_LOG__0, e));
m.tail = "";
}
return m;
}
Aggregations