Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,10 @@ CodeCompass_webserver \

The server will be available in a browser on
[`http://localhost:6251`](http://localhost:6251).

### Logging

In both the parser and the webserver it is possible to write the logs to a given directory.
This feature can be enabled by passing the `--logtarget` command line option with the full
path to the directory to be used for storing the log files.
If this argument is not specified, the logs will be written to the terminal only.
16 changes: 15 additions & 1 deletion parser/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ po::options_description commandLineArguments()
po::value<trivial::severity_level>()->default_value(trivial::info),
"Logging legel of the parser. Possible values are: debug, info, warning, "
"error, critical.")
("logtarget", po::value<std::string>(),
"This is the path to the folder where the logging output files will be written. "
"If omitted, the output will be on the console only.")
("jobs,j", po::value<int>()->default_value(4),
"Number of threads the parsers can use.")
("skip,s", po::value<std::vector<std::string>>(),
Expand Down Expand Up @@ -219,7 +222,7 @@ int main(int argc, char* argv[])

cc::parser::PluginHandler pHandler(PARSER_PLUGIN_DIR);

cc::util::initLogger();
cc::util::initConsoleLogger();

//--- Process command line arguments ---//

Expand All @@ -229,6 +232,17 @@ int main(int argc, char* argv[])
po::store(po::command_line_parser(argc, argv)
.options(desc).allow_unregistered().run(), vm);

if (vm.count("logtarget"))
{
vm.at("logtarget").value() = cc::util::getLoggingBase( vm["logtarget"].as<std::string>()
, vm["name"].as<std::string>()
);
if (!cc::util::initFileLogger(vm["logtarget"].as<std::string>() + "parser.log"))
{
vm.at("logtarget").value() = std::string();
}
}

//--- Skip parser list ---//

std::vector<std::string> skipParserList;
Expand Down
1 change: 1 addition & 0 deletions plugins/search/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_jar(searchcommonjava
${CMAKE_CURRENT_SOURCE_DIR}/src/cc/search/analysis/Location.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cc/search/analysis/SourceTextAnalyzer.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cc/search/analysis/SourceTextTokenizer.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cc/search/common/FileLoggerInitializer.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cc/search/common/IndexFields.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cc/search/common/SuggestionDatabase.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cc/search/common/NFSFriendlyLockFactory.java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cc.search.common;

import cc.search.common.config.CommonOptions;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.FileHandler;
import java.util.logging.SimpleFormatter;

/**
* Adds file to logging when needed
*/
public class FileLoggerInitializer {
public static void addFileOutput(CommonOptions options_, Logger log_, String pluginName_) {
String filePathField = options_.logFilePath + pluginName_ + ".log";
if (!options_.logFilePath.isEmpty()) {
try {
FileHandler fileHandler = new FileHandler(filePathField, false);
SimpleFormatter formatter = new SimpleFormatter();
fileHandler.setFormatter(formatter);
log_.addHandler(fileHandler);
log_.info("Logging started to file: " + filePathField);
} catch (Exception ex) {
log_.log(Level.WARNING, "Could not add logs to file: " + filePathField, ex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public abstract class CommonOptions {
* Index database path
*/
public String indexDirPath;
/**
* Logging file path
* (if there is no file logging, empty string)
*/
public String logFilePath = "";
/**
* Input file descriptor for thrift IPC.
*/
Expand Down Expand Up @@ -77,6 +82,15 @@ protected void setFromCommandLineArguments(List<String> args_)
argIter.remove();
}
break;
case "-logTarget":
if (!argIter.hasNext()) {
throw new InvalidValueException("No path for -logTarget");
} else {
argIter.remove();
logFilePath = argIter.next();
argIter.remove();
}
break;
case "-ipcInFd":
if (!argIter.hasNext()) {
throw new InvalidValueException("-ipcInFd is empty");
Expand Down Expand Up @@ -136,6 +150,7 @@ public static String getUsage() {
+ "\t-ipcInFd fd\n\t\tFile descriptor for IPC IN.\n"
+ "\t-ipcOutFd id\n\t\tFile descriptor for IPC OUT.\n"
+ "\t-useSimpleFileLock\n\t\tUse NFS friendly file locks.\n"
+ "\t-logTarget\n\t\tPath to logging file.\n"
+ "\t-cleanupLocks\n\t\tCleanup locks before first lock..\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LogConfigurator() {
logManager.readConfiguration(cfgStream);

} catch (IOException | SecurityException ex) {
Logger.getLogger(LogConfigurator.class.getName()).log(Level.SEVERE,
Logger.getGlobal().log(Level.SEVERE,
"Failed to configure custom log propeties!", ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class IPCProcessor implements AutoCloseable {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(
IPCProcessor.class.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Processor for thrift messages.
*/
Expand Down
3 changes: 2 additions & 1 deletion plugins/search/indexer/include/indexer/indexerprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class IndexerProcess :
const std::string& indexDatabase_,
const std::string& compassRoot_,
OpenMode openMode_,
LockMode lockMode_ = LockMode::Simple);
LockMode lockMode_ = LockMode::Simple,
const std::string& logTarget_ = "");

/**
* Closes the I/O pipe so the child process will exit if it finished. Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public final class SourceAnalyzer extends AnalyzerWrapper {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(SourceAnalyzer.class
.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Analyzer for a full path.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class CTags implements TagGenerator {
/**
* Logger.
*/
private final static Logger _log = Logger.getLogger(CTags.class
.getName());
private final static Logger _log = Logger.getGlobal();
/**
* Filter terminator string for ctags.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class SourceTagGenerator implements TagGenerator {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(SourceTagGenerator.class
.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Options array for initializing _artf460600CTags.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public final class TagGeneratorManager implements AutoCloseable {
/**
* Logger.
*/
private final static Logger _log = Logger.getLogger(
TagGeneratorManager.class.getName());
private final static Logger _log = Logger.getGlobal();
/**
* Singleton instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ abstract public class AbstractIndexer {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(AbstractIndexer
.class.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Field type for storing tags.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class FileIndexer extends AbstractIndexer {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(FileIndexer.class
.getName());
private static final Logger _log = Logger.getGlobal();
/**
* File path to index.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cc.parser.search.IndexerService;
import cc.search.analysis.SourceAnalyzer;
import cc.search.analysis.tags.TagGeneratorManager;
import cc.search.common.FileLoggerInitializer;
import cc.search.common.ipc.IPCProcessor;
import cc.search.common.config.InvalidValueException;
import cc.search.common.config.UnknownArgumentException;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class Indexer implements AutoCloseable, IndexerService.Iface {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(Indexer.class.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Command line options.
*/
Expand Down Expand Up @@ -82,6 +83,8 @@ public class Indexer implements AutoCloseable, IndexerService.Iface {
private Indexer(Options options_) throws IOException {
_options = options_;

FileLoggerInitializer.addFileOutput(_options, _log, "indexer");

try {
_indexDir = FSDirectory.open(new File(_options.indexDirPath),
_options.createLockFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public final class DatabaseBuilder {
/**
* Logger.
*/
private static final Logger _log
= Logger.getLogger(DatabaseBuilder.class.getName());
private static final Logger _log = Logger.getGlobal();
/**
* An index reader for the main index database.
*/
Expand Down
8 changes: 5 additions & 3 deletions plugins/search/indexer/src/indexerprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ IndexerProcess::IndexerProcess(
const std::string& indexDatabase_,
const std::string& compassRoot_,
IndexerProcess::OpenMode openMode_,
IndexerProcess::LockMode lockMode_)
IndexerProcess::LockMode lockMode_,
const std::string& logTarget_)
{
openPipe(_pipeFd2[0], _pipeFd2[1]);

Expand Down Expand Up @@ -60,12 +61,13 @@ IndexerProcess::IndexerProcess(
"java", JAVAMEMORYAMOUNT,
"-classpath", classpath.c_str(),
"-Djava.util.logging.config.class=cc.search.common.config.LogConfigurator",
"-Djava.util.logging.SimpleFormatter.format=[%4$s] %5$s%6$s%n",
"-Djava.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tT [%4$s] %5$s%6$s%n",
logLevelOpt.c_str(),
"cc.search.indexer.app.Indexer",
"-indexDB", indexDatabase_.c_str(),
"-ipcInFd", inFd.c_str(),
"-ipcOutFd", outFd.c_str()
"-ipcOutFd", outFd.c_str(),
"-logTarget", logTarget_.c_str()
};

switch (openMode_)
Expand Down
6 changes: 5 additions & 1 deletion plugins/search/parser/src/searchparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ SearchParser::SearchParser(ParserContext& ctx_) : AbstractParser(ctx_),
_indexProcess.reset(new IndexerProcess(
_searchDatabase,
ctx_.compassRoot,
IndexerProcess::OpenMode::Create));
IndexerProcess::OpenMode::Create,
IndexerProcess::LockMode::Simple,
ctx_.options.count("logtarget")
? ctx_.options["logtarget"].as<std::string>()
: ""));
}
catch (const IndexerProcess::Failure& ex_)
{
Expand Down
6 changes: 4 additions & 2 deletions plugins/search/service/include/service/serviceprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ServiceProcess : public SearchServiceIf, public util::PipedProcess
* @param indexDatabase_ path to a index database
*/
ServiceProcess(const std::string& indexDatabase_,
const std::string& compassRoot_) :
const std::string& compassRoot_,
const std::string& logTarget_ = "") :
_indexDatabase(indexDatabase_)
{
openPipe(_pipeFd2[0], _pipeFd2[1]);
Expand Down Expand Up @@ -63,14 +64,15 @@ class ServiceProcess : public SearchServiceIf, public util::PipedProcess
"-classpath", classpath.c_str(),
//"-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8666",
"-Djava.util.logging.config.class=cc.search.common.config.LogConfigurator",
"-Djava.util.logging.SimpleFormatter.format=[%4$s] %5$s%6$s%n",
"-Djava.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tT [%4$s] %5$s%6$s%n",
logLevelOpt.c_str(),
"cc.search.service.app.service.ServiceApp",
"-indexDB", _indexDatabase.c_str(),
"-ipcInFd", inFd.c_str(),
"-ipcOutFd", outFd.c_str(),
"-useSimpleFileLock",
"-cleanupLocks",
"-logTarget", logTarget_.c_str(),
nullptr);

LOG(error) << "execlp failed!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class QueryAnalyzer extends AnalyzerWrapper {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(QueryAnalyzer.class.
getName());
private static final Logger _log = Logger.getGlobal();
/**
* A simple analyzer for queries.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public class HIPDQuery extends Query {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(HIPDQuery.class.
getName());
private static final Logger _log = Logger.getGlobal();
/**
* The default value of the maximal allowed difference.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class MasterMatcherFactory implements ResultMatcherFactory {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(MasterMatcherFactory.
class.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Matcher wrapper for matching with multiple matchers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class TagKindMatcherFactory implements ResultMatcherFactory {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(TagKindMatcherFactory.
class.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Token filter for filtering relevant tokens by its kind.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public abstract class SearchAppCommon implements AutoCloseable {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(SearchAppCommon.class
.getName());
private static final Logger _log = Logger.getGlobal();

/**
* Async task class for matching lines in a document.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.search.service.app.query;

import cc.search.service.app.SearchAppCommon;
import cc.search.common.FileLoggerInitializer;
import cc.search.common.config.InvalidValueException;
import cc.search.common.config.UnknownArgumentException;
import cc.search.match.QueryContext;
Expand All @@ -22,7 +23,7 @@ public class QueryApp extends SearchAppCommon {
/**
* Logger.
*/
private static final Logger _log = Logger.getLogger(QueryApp.class.getName());
private static final Logger _log = Logger.getGlobal();
/**
* Application options.
*/
Expand All @@ -35,6 +36,7 @@ public class QueryApp extends SearchAppCommon {
private QueryApp(QueryAppOptions options_) throws IOException {
super(options_);
_appOptions = options_;
FileLoggerInitializer.addFileOutput(options_, _log, "query");
}

/**
Expand Down
Loading