text
stringlengths
0
2.2M
}
} // close package namespace
} // close enterprise namespace
// ----------------------------------------------------------------------------
// Copyright 2018 Bloomberg Finance L.P.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------- END-OF-FILE ----------------------------------
#include "ofLog.h"
#include "ofConstants.h"
#include <ofUtils.h>
#include <map>
#include <cstdarg>
#ifdef TARGET_ANDROID
#include "ofxAndroidLogChannel.h"
#endif
using namespace std;
static ofLogLevel currentLogLevel = OF_LOG_NOTICE;
bool ofLog::bAutoSpace = false;
string & ofLog::getPadding() {
static string * padding = new string;
return *padding;
}
static map<string,ofLogLevel> & getModules(){
static map<string,ofLogLevel> * modules = new map<string,ofLogLevel>;
return *modules;
}
static void noopDeleter(ofBaseLoggerChannel*){}
shared_ptr<ofBaseLoggerChannel> & ofLog::channel(){
#ifdef TARGET_ANDROID
static shared_ptr<ofBaseLoggerChannel> channel = shared_ptr<ofxAndroidLogChannel>(new ofxAndroidLogChannel, std::function<void(ofBaseLoggerChannel *)>(noopDeleter));
#elif defined(TARGET_WIN32)
static shared_ptr<ofBaseLoggerChannel> channel = IsDebuggerPresent() ? shared_ptr<ofBaseLoggerChannel>(new ofDebugViewLoggerChannel, std::function<void(ofBaseLoggerChannel *)>(noopDeleter)) : shared_ptr<ofBaseLoggerChannel>(new ofConsoleLoggerChannel, std::function<void(ofBaseLoggerChannel *)>(noopDeleter));
#else
static shared_ptr<ofBaseLoggerChannel> channel = shared_ptr<ofConsoleLoggerChannel>(new ofConsoleLoggerChannel, std::function<void(ofBaseLoggerChannel *)>(noopDeleter));
#endif
return channel;
}
//--------------------------------------------------
void ofSetLogLevel(ofLogLevel level){
currentLogLevel = level;
}
//--------------------------------------------------
void ofSetLogLevel(string module, ofLogLevel level){
getModules()[module] = level;
}
//--------------------------------------------------
ofLogLevel ofGetLogLevel(){
return currentLogLevel;
}
//--------------------------------------------------
ofLogLevel ofGetLogLevel(string module){
if (getModules().find(module) == getModules().end()) {
return currentLogLevel;
} else {
return getModules()[module];
}
}
//--------------------------------------------------
void ofLogToFile(const std::filesystem::path & path, bool append){
ofLog::setChannel(std::make_shared<ofFileLoggerChannel>(path,append));
}
//--------------------------------------------------
void ofLogToConsole(){
ofLog::setChannel(shared_ptr<ofConsoleLoggerChannel>(new ofConsoleLoggerChannel, std::function<void(ofBaseLoggerChannel *)>(noopDeleter)));
}
#ifdef TARGET_WIN32
void ofLogToDebugView() {
ofLog::setChannel(shared_ptr<ofDebugViewLoggerChannel>(new ofDebugViewLoggerChannel, std::function<void(ofBaseLoggerChannel *)>(noopDeleter)));
}
#endif