Beispiel #1
0
void Logger::enableFileLogging(const std::string& fileName, int level)
{
    Mutex::ScopedLock lock(loggerMutex);

    Logger::setLevel(level);

    // close the current file log and re-create it.
    disableFileLogging();

    if (!simpleFileChannel)
    {
        std::string realName;

        // figure out what file name to use
        if (fileName.length() == 0) {
            // none given, use one from config.
            realName = Config::getString(Config::LOGGER_LOG_FILE_PATH);
        } else {
            realName = fileName;
        }

        if (realName.length() == 0) {
            // default log name.
            realName = joinPath(getTempDir(), "roadrunner.log");
        } else {
            // expand any env vars and make absolute path.
            realName = Poco::Path::expand(realName);
            Poco::Path path(realName);
            realName = path.makeAbsolute().toString();
        }

        // check if the path is writable
        Poco::Path p(realName);
        Poco::File fdir = p.parent();
        if(!fdir.exists())
        {
            realName = joinPath(getTempDir(), "roadrunner.log");
            Log(Logger::LOG_ERROR) << "The specified log file directory path, "
                    << fdir.path() << " does not exist, using default log file path: "
                    << realName;
        }

        SplitterChannel *splitter = getSplitterChannel();

        simpleFileChannel = new SimpleFileChannel();
        simpleFileChannel->setProperty("path", realName);
        simpleFileChannel->setProperty("rotation", "never");

        logFileName = simpleFileChannel->getProperty("path");

        splitter->addChannel(simpleFileChannel);
        simpleFileChannel->release();
    }
}
Beispiel #2
0
void Logger::disableConsoleLogging()
{
    Mutex::ScopedLock lock(loggerMutex);

    if (consoleChannel)
    {
        SplitterChannel *splitter = getSplitterChannel();
        assert(splitter && "could not get splitter channel from logger");

        splitter->removeChannel(consoleChannel);
        consoleChannel = 0;
    }
}
Beispiel #3
0
void Logger::disableFileLogging()
{
    Mutex::ScopedLock lock(loggerMutex);

    if (simpleFileChannel)
    {
        SplitterChannel *splitter = getSplitterChannel();

        splitter->removeChannel(simpleFileChannel);
        simpleFileChannel = 0;
        logFileName = "";
    }
}
Beispiel #4
0
void Logger::disableLogging()
{
    Mutex::ScopedLock lock(loggerMutex);

    getLogger();

    SplitterChannel *splitter = getSplitterChannel();

    splitter->close();

    consoleChannel = 0;
    simpleFileChannel = 0;
    logFileName = "";
}
Beispiel #5
0
void Logger::enableConsoleLogging(int level)
{
    Mutex::ScopedLock lock(loggerMutex);

    Logger::setLevel(level);

    if (!consoleChannel)
    {
        SplitterChannel *splitter = getSplitterChannel();

        // default is console channel
        consoleChannel = createConsoleChannel();

        // let the logger manage ownership of the channels, we keep then around
        // so we can know when to add or remove them.
        splitter->addChannel(consoleChannel);

        consoleChannel->release();
    }
}
Beispiel #6
0
void Logger::enableFileLogging(const std::string& fileName, int level)
{
    Mutex::ScopedLock lock(loggerMutex);

    Logger::setLevel(level);

    if (!simpleFileChannel)
    {
        SplitterChannel *splitter = getSplitterChannel();

        simpleFileChannel = new SimpleFileChannel();
        simpleFileChannel->setProperty("path", fileName);
        simpleFileChannel->setProperty("rotation", "never");

        logFileName = simpleFileChannel->getProperty("path");

        splitter->addChannel(simpleFileChannel);
        simpleFileChannel->release();
    }
}