<commit_before>/*
 * Copyright (C) 2008, 2009 Nokia Corporation.
 *
 * Contact: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include "logging.h"
#include <stdio.h>
#include <stdlib.h>
#include <QDateTime>

/*!
    \page Logging
    
    \brief The library (and ContexKit in general) use a simple logging system designed 
    to unify the output and make the debugging easier.
    
    \section API
    
    Four types of log messages (presented here in the order of importance) are supported: 
    \b Test, \b Debug, \b Warning and \b Critical. 
    
    The first one, the \b Test message requires some attention. It's meant to be used 
    from tests and unit-tests to log various stages of the test execution. It'll make
    the test output more easily filterable.
    
    The log messages can be used like this:
    
    \code
    contextTest() << "This is some message";
    contextDebug() << "My value is:" << someVariable;
    contextWarning() << "Expecting key:" << something.getKey();
    contextCritical() << 5 << " is bigger than " << 4;
    \endcode
    
    \section compilecontrol Compile-time verbosity control
    
    During the compile time certain defines can be used to turn-off debug messages. 
    Those defines are:
    
    \code
    CONTEXT_LOG_HIDE_TEST
    CONTEXT_LOG_HIDE_DEBUG
    CONTEXT_LOG_HIDE_WARNING
    CONTEXT_LOG_HIDE_CRITICAL
    \endcode
    
    A given define makes a respective macro message evaluate to an empty code. To be precise:
    it makes the macro message evaluate to an inline do-nothing class that is optimized by the
    compiler to do nothing.
    
    When ie. \c CONTEXT_LOG_HIDE_DEBUG define is used to turn off \c contextDebug()
    messages, the actual string content of the debug messages is \b not included in the binary 
    and during runtime the machine does not spend time evaluating it.
    
    Those compile-time control defines are integrated in the build/configure system.
    
    \section runtimecontrol Run-time verbosity control
    
    During run-time, the amount of debugging can be limited (filtered) but it can't be increased
    (expanded). In other words, if a package was compiled with warnings-only, it's not possible 
    to make it show debug messages at runtime. But it is possible to make it criticals-only. 
    
    The filtering happens via env variables. The major player is the \c CONTEXT_LOG_VERBOSITY variable
    which can be set to \c TEST, \c DEBUG, \c WARNING and \c CRITICAL. The \c CONTEXT_LOG_VERBOSITY 
    specifies the minimal level of the messages shown. Ie. \c CONTEXT_LOG_VERBOSITY set to 
    \c WARNING will show only warning and criticals. 
    
    The format of the output can be tweaked with \c CONTEXT_LOG_HIDE_TIMESTAMPS and \c CONTEXT_LOG_USE_COLOR. 
    The first one makes the messages shorter by skipping the timestamp info. The second one adds a 
    little bit of ANSI coloring to the messages.
    
    \c CONTEXT_LOG_SHOW_MODULE will filter-out (kill) all messages \b except the ones coming from the 
    specified module. Ie.:
    
    \code
    CONTEXT_LOG_SHOW_MODULE=subscriber ./some-binary
    \endcode
    
    ...will run \c ./some-binary showing log messages \b only from \c subscriber module.
    
    Lastly, \c CONTEXT_LOG_HIDE_MODULE will hide log messages coming from the specified module. 
    All other messages will be show.
*/

/* NullIODevice */

/*!
    \class NullIODevice  

    \brief Device that kills all input.

    This class is a \c QIODevice implementation that kills everything sent to it. 
    We set this as a output device for stream in ContextRealLogger when given debug
    message type was disabled at \b runtime. 
*/

qint64 NullIODevice::readData(char*, qint64)
{
    return 0;
}

qint64 NullIODevice::writeData(const char*, qint64)
{ 
    return 0; 
}

/* ContextRealLogger */

/*!
    \class ContextRealLogger
<commit_msg>Updating the documentation about modules.<commit_after>/*
 * Copyright (C) 2008, 2009 Nokia Corporation.
 *
 * Contact: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include "logging.h"
#include <stdio.h>
#include <stdlib.h>
#include <QDateTime>

/*!
    \page Logging
    
    \brief The library (and ContexKit in general) use a simple logging system designed 
    to unify the output and make the debugging easier.
    
    \section API
    
    Four types of log messages (presented here in the order of importance) are supported: 
    \b Test, \b Debug, \b Warning and \b Critical. 
    
    The first one, the \b Test message requires some attention. It's meant to be used 
    from tests and unit-tests to log various stages of the test execution. It'll make
    the test output more easily filterable.
    
    The log messages can be used like this:
    
    \code
    contextTest() << "This is some message";
    contextDebug() << "My value is:" << someVariable;
    contextWarning() << "Expecting key:" << something.getKey();
    contextCritical() << 5 << " is bigger than " << 4;
    \endcode
    
    \section compilecontrol Compile-time verbosity control
    
    During the compile time certain defines can be used to turn-off debug messages. 
    Those defines are:
    
    \code
    CONTEXT_LOG_HIDE_TEST
    CONTEXT_LOG_HIDE_DEBUG
    CONTEXT_LOG_HIDE_WARNING
    CONTEXT_LOG_HIDE_CRITICAL
    \endcode
    
    A given define makes a respective macro message evaluate to an empty code. To be precise:
    it makes the macro message evaluate to an inline do-nothing class that is optimized by the
    compiler to do nothing.
    
    When ie. \c CONTEXT_LOG_HIDE_DEBUG define is used to turn off \c contextDebug()
    messages, the actual string content of the debug messages is \b not included in the binary 
    and during runtime the machine does not spend time evaluating it.
    
    Those compile-time control defines are integrated in the build/configure system.
    
    \section runtimecontrol Run-time verbosity control
    
    During run-time, the amount of debugging can be limited (filtered) but it can't be increased
    (expanded). In other words, if a package was compiled with warnings-only, it's not possible 
    to make it show debug messages at runtime. But it is possible to make it criticals-only. 
    
    The filtering happens via env variables. The major player is the \c CONTEXT_LOG_VERBOSITY variable
    which can be set to \c TEST, \c DEBUG, \c WARNING and \c CRITICAL. The \c CONTEXT_LOG_VERBOSITY 
    specifies the minimal level of the messages shown. Ie. \c CONTEXT_LOG_VERBOSITY set to 
    \c WARNING will show only warning and criticals. 
    
    The format of the output can be tweaked with \c CONTEXT_LOG_HIDE_TIMESTAMPS and \c CONTEXT_LOG_USE_COLOR. 
    The first one makes the messages shorter by skipping the timestamp info. The second one adds a 
    little bit of ANSI coloring to the messages.
    
    \c CONTEXT_LOG_SHOW_MODULE will filter-out (kill) all messages \b except the ones coming from the 
    specified module. Ie.:
    
    \code
    CONTEXT_LOG_SHOW_MODULE=subscriber ./some-binary
    \endcode
    
    ...will run \c ./some-binary showing log messages \b only from \c subscriber module.
    
    Lastly, \c CONTEXT_LOG_HIDE_MODULE will hide log messages coming from the specified module. 
    All other messages will be show.

    \section modules Modules in logging

    In previous section we discussed and mentioned modules. For the purpose of logging, 
    a module is a piece of code (not neccesarily limited to one binary or shared object) that
    forms one component (feature-wise). Specyfying and naming the modules is used
    to set the origin of the logging messages. 

    The logging module is set using the \c CONTEXT_LOG_MODULE_NAME define. It should be
    (in most cases) defined in the build system and automatically applied to the whole source code. 
    Typically (with autotools) this can be achieved with something similar too:

    \code
    ...
    AM_CXXFLAGS = '-DCONTEXT_LOG_MODULE_NAME="libtest"'
    ...
    \endcode
    
    If \c CONTEXT_LOG_MODULE_NAME is undefined, the log messages will be marked as coming from an
    \b "Undefined" module.
*/

/* NullIODevice */

/*!
    \class NullIODevice  

    \brief Device that kills all input.

    This class is a \c QIODevice implementation that kills everything sent to it. 
    We set this as a output device for stream in ContextRealLogger when given debug
    message type was disabled at \b runtime. 
*/

qint64 NullIODevice::readData(char*, qint64)
{
    return 0;
}

qint64 NullIODevice::writeData(const char*, qint64)
{ 
    return 0; 
}

/* ContextRealLogger */

/*!
    \class ContextRealLogger

{'fraction_non_alphanumeric': 0.058180359113251076, 'fraction_numerical': 0.0066205236232320195, 'mean_word_length': 2.9927913496195435, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195672', 'n_tokens_mistral': 2850, 'n_tokens_neox': 2706, 'n_words': 1318}