English 中文(简体)
多份申请写给一个独角——混合/目标产出
原标题:Multiple applications write to one console - mixed/messed output

我有以下系统结构(无法改变——遗产法): 一项主要申请援引了一项或多项其他申请,这些申请与一项IP协议具有互动关系。

All applications write to one console window. Unfortunately the console output can get messed up (one character from app 1, next char from app 2, next character from app 4 etc.). All applications write to console via one Logger.dll (provides static logging functions) using cout/cerr.

我如何防止这一设置中的混合伐木信息?

提前报到。

http://www.ohchr.org。 加入:

void Logger::Log(const std::string & componentName, const std::string & Text, LogLevel logLevel, bool logToConsole, bool beep) 
{   
    std::ostringstream stream;

    switch (logLevel)
    {   
        case LOG_INFO:

            if (logToConsole) 
            {
                 stream << componentName << ": INFO " << Text;
                 mx_console.lock(); // this is a static boost::mutex
                 std::cout << stream.str() << std::endl;
                 std::cout.flush();
                 mx_console.unlock();
            }
            break;

       case LOG_STATUS: 

            stream << componentName << ": STATUS " << Text;
            mx_console.lock();
            std::cout << stream.str() << std::endl;
            std::cout.flush();
            mx_console.unlock();
            break;

       case LOG_WARNING:

            stream << componentName << ": WARNING " << Text;
            mx_console.lock();
            std::cout << stream.str() << std::endl;
            std::cout.flush();
            mx_console.unlock();
            break;

       default:;
     }

    if (beep)
         Beep( 500, 50 ); 
}
最佳回答

我现在取而代之。

std::cout << stream.str();

声明

std::string str = stream.str();
printf(str.c_str());

and now the output isn t messed up character-wise anymore. But I don t have a good explanation for this behavior, does anybody know why?

问题回答

Since you have separate logging functionality you can at minimum use some kind of locking (global mutex, etc.) to avoid interspersing messages from different applications too much. To make it more readable and grepable, add some identifying information, like process name or PID. Wrapping your Logger.dll around existing logging library sounds like an option as well.

或者,你可以有伐木功能,只是向你们的主要应用传递信息,让你能够展示同步和相互协调。

道歉可能是你们的一种解决办法,因为它意在处理来自不同地点的标志。 锡斯洛用于不成像,但

你们可以改变记录,而不是ole。





相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签