当前位置: 首页>>代码示例>>C++>>正文


C++ logger::set_level方法代码示例

本文整理汇总了C++中logger::set_level方法的典型用法代码示例。如果您正苦于以下问题:C++ logger::set_level方法的具体用法?C++ logger::set_level怎么用?C++ logger::set_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logger的用法示例。


在下文中一共展示了logger::set_level方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    // tell the logger to output all messages
    dlog.set_level(LALL);

    // Create an instance of our multi-threaded object.   
    my_object t;

    dlib::sleep(3000);
    
    // Tell the multi-threaded object to pause its threads.  This causes the
    // threads to block on their next calls to should_stop().
    t.pause();
    dlog << LINFO << "paused threads";

    dlib::sleep(3000);
    dlog << LINFO << "starting threads back up from paused state";

    // Tell the threads to unpause themselves.  This causes should_stop() to unblock 
    // and to let the threads continue.
    t.start();

    dlib::sleep(3000);

    // Let the program end.  When t is destructed it will gracefully terminate your
    // threads because we have set the destructor up to do so.
}
开发者ID:20337112,项目名称:dlib,代码行数:27,代码来源:multithreaded_object_ex.cpp

示例2: main

int main()
{
    // Every logger has a logging level (given by dlog.level()).  Each log message is tagged with a
    // level and only levels equal to or higher than dlog.level() will be printed.  By default all 
    // loggers start with level() == LERROR.  In this case I'm going to set the lowest level LALL 
    // which means that dlog will print all logging messages it gets.
    dlog.set_level(LALL);


    // print our first message.  It will go to cout because that is the default.
    dlog << LINFO << "This is an informational message.";

    // now print a debug message.
    int variable = 8;
    dlog << LDEBUG << "The integer variable is set to " << variable;

    // the logger can be used pretty much like any ostream object.  But you have to give a logging
    // level first.  But after that you can chain << operators like normal.
    
    if (variable > 4)
        dlog << LWARN << "The variable is bigger than 4!  Its value is " << variable;



    dlog << LINFO << "we are going to sleep for half a second.";
    // sleep for half a second
    dlib::sleep(500);
    dlog << LINFO << "we just woke up";



    dlog << LINFO << "program ending";
}
开发者ID:ComputerLover108,项目名称:ComputerLover,代码行数:33,代码来源:dlog.cpp

示例3: main

int main()
{
    // tell the logger to print out everything
    dlog.set_level(LALL);


    dlog << LINFO << "schedule a few tasks";

    test mytask;
    // Schedule the thread pool to call mytask.task().  Note that all forms of add_task()
    // pass in the task object by reference.  This means you must make sure, in this case,
    // that mytask isn't destructed until after the task has finished executing.
    tp.add_task(mytask, &test::task);

    // You can also pass task objects to a thread pool by value.  So in this case we don't
    // have to worry about keeping our own instance of the task.  Here we construct a temporary 
    // add_value object and pass it right in and everything works like it should.
    future<int> num = 3;
    tp.add_task_by_value(add_value(7), num);  // adds 7 to num
    int result = num.get();
    dlog << LINFO << "result = " << result;   // prints result = 10





// uncomment this line if your compiler supports the new C++0x lambda functions
//#define COMPILER_SUPPORTS_CPP0X_LAMBDA_FUNCTIONS
#ifdef COMPILER_SUPPORTS_CPP0X_LAMBDA_FUNCTIONS

    // In the above examples we had to explicitly create task objects which is
    // inconvenient.  If you have a compiler which supports C++0x lambda functions
    // then you can use the following simpler method.

    // make a task which will just log a message
    tp.add_task_by_value([](){
                         dlog << LINFO << "A message from a lambda function running in another thread."; 
                         });

    // Here we make 10 different tasks, each assigns a different value into 
    // the elements of the vector vect.
    std::vector<int> vect(10);
    for (unsigned long i = 0; i < vect.size(); ++i)
    {
        // Make a lambda function which takes vect by reference and i by value.  So what
        // will happen is each assignment statement will run in a thread in the thread_pool.
        tp.add_task_by_value([&vect,i](){
                             vect[i] = i;
                             });
    }
    // Wait for all tasks which were requested by the main thread to complete.
    tp.wait_for_all_tasks();
    for (unsigned long i = 0; i < vect.size(); ++i)
    {
        dlog << LINFO << "vect["<<i<<"]: " << vect[i];
    }
#endif



    /* A possible run of this program might produce the following output (the first column is 
       the time the log message occurred and the value in [] is the thread id for the thread
       that generated the log message):

    1 INFO  [0] main: schedule a few tasks
    1 INFO  [1] main: task start
    1 INFO  [0] main: result = 10
  201 INFO  [2] main: subtask end 
  201 INFO  [1] main: var = 2
  201 INFO  [2] main: A message from a lambda function running in another thread.
  301 INFO  [3] main: subtask2 end 
  301 INFO  [1] main: task end
  301 INFO  [0] main: vect[0]: 0
  301 INFO  [0] main: vect[1]: 1
  301 INFO  [0] main: vect[2]: 2
  301 INFO  [0] main: vect[3]: 3
  301 INFO  [0] main: vect[4]: 4
  301 INFO  [0] main: vect[5]: 5
  301 INFO  [0] main: vect[6]: 6
  301 INFO  [0] main: vect[7]: 7
  301 INFO  [0] main: vect[8]: 8
  301 INFO  [0] main: vect[9]: 9
    */
}
开发者ID:Abai,项目名称:dlib,代码行数:84,代码来源:thread_pool_ex.cpp


注:本文中的logger::set_level方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。