<commit_before>/*
 * $Id$
 *
 * Serial Wire Debug Open Library.
 * Library Body File.
 *
 * Copyright (C) 2010-2011, <NAME> (http://www.tomek.cedro.info)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. Neither the name of the Tomasz Boleslaw CEDRO nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.*
 *
 * Written by <NAME> <<EMAIL>>, 2010-2011;
 *
 */

/** \file libswd_log.c */

#include <libswd.h>

/*******************************************************************************
 * \defgroup swd_log Miscelanous logging functionalities.
 * @{
 ******************************************************************************/

/** Logging functionality can be external or internal, by default external
 * function can be defined to use target program logging mechanism.
 * To use internal logging mechanism simply wrap swd_log_internal() around
 * this function in application specific driver bridge file,
 * see libswd_externs.c for examples.
 */
extern int swd_log(swd_ctx_t *swdctx, swd_loglevel_t loglevel, char *msg, ...);

/** Put a message into swd context log at specified verbosity level.
 * If specified message's log level is lower than actual context configuration,
 * message will be omitted. Verbosity level increases from 0 (silent) to 4 (debug).
 * \param *swdctx swd context.
 * \param loglevel at which to put selected message.
 * \param *msg message body with variable arguments as in "printf".
 * \return number of characters written or error code on failure.
 */
int swd_log_internal(swd_ctx_t *swdctx, swd_loglevel_t loglevel, char *msg, ...){
 if (loglevel<SWD_LOGLEVEL_MIN && loglevel>SWD_LOGLEVEL_MAX)
  return SWD_ERROR_LOGLEVEL;
 if (loglevel > swdctx->config.loglevel) return SWD_OK;
 int res;
 va_list ap;
 va_start(ap, msg);
 res=vprintf(msg, ap);  
 va_end(ap);
 return res;
}

/** Change log level to increase or decrease verbosity level.
 * \param *swdctx swd context.
 * \param loglevel is the target verbosity level to be set.
 * \return SWD_OK on success or error code.
 */

int swd_log_level_set(swd_ctx_t *swdctx, swd_loglevel_t loglevel){
 if (swdctx==NULL) return SWD_ERROR_NULLCONTEXT;
 if (loglevel<SWD_LOGLEVEL_MIN && loglevel>SWD_LOGLEVEL_MAX)
  return SWD_ERROR_LOGLEVEL;

 swdctx->config.loglevel=loglevel;
 swd_log(swdctx, SWD_LOGLEVEL_NORMAL, "SWD LogLevel[%d..%d] set to: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel));
 return SWD_OK;
}

const char *swd_log_level_string(swd_loglevel_t loglevel){
 switch (loglevel){
  case SWD_LOGLEVEL_SILENT: return "SWD_LOGLEVEL_SILENT";
  case SWD_LOGLEVEL_ERROR:  return "SWD_LOGLEVEL_ERROR";
  case SWD_LOGLEVEL_WARNING: return "SWD_LOGLEVEL_WARNING";
  case SWD_LOGLEVEL_NORMAL:  return "SWD_LOGLEVEL_NORMAL";
  case SWD_LOGLEVEL_INFO:    return "SWD_LOGLEVEL_INFO";
  case SWD_LOGLEVEL_DEBUG:   return "SWD_LOGLEVEL_DEBUG";
 }
 return "UNKNOWN LOGLEVEL!";
};


/** @} */
<commit_msg>Minor fix in reporting loglevel change at debug level instead normal output that was disturbing.<commit_after>/*
 * $Id$
 *
 * Serial Wire Debug Open Library.
 * Library Body File.
 *
 * Copyright (C) 2010-2011, <NAME> CEDRO (http://www.tomek.cedro.info)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. Neither the name of the Tomasz Boleslaw CEDRO nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.*
 *
 * Written by <NAME> CEDRO <<EMAIL>>, 2010-2011;
 *
 */

/** \file libswd_log.c */

#include <libswd.h>

/*******************************************************************************
 * \defgroup swd_log Miscelanous logging functionalities.
 * @{
 ******************************************************************************/

/** Logging functionality can be external or internal, by default external
 * function can be defined to use target program logging mechanism.
 * To use internal logging mechanism simply wrap swd_log_internal() around
 * this function in application specific driver bridge file,
 * see libswd_externs.c for examples.
 */
extern int swd_log(swd_ctx_t *swdctx, swd_loglevel_t loglevel, char *msg, ...);

/** Put a message into swd context log at specified verbosity level.
 * If specified message's log level is lower than actual context configuration,
 * message will be omitted. Verbosity level increases from 0 (silent) to 4 (debug).
 * \param *swdctx swd context.
 * \param loglevel at which to put selected message.
 * \param *msg message body with variable arguments as in "printf".
 * \return number of characters written or error code on failure.
 */
int swd_log_internal(swd_ctx_t *swdctx, swd_loglevel_t loglevel, char *msg, ...){
 if (loglevel<SWD_LOGLEVEL_MIN && loglevel>SWD_LOGLEVEL_MAX)
  return SWD_ERROR_LOGLEVEL;
 if (loglevel > swdctx->config.loglevel) return SWD_OK;
 int res;
 va_list ap;
 va_start(ap, msg);
 res=vprintf(msg, ap);  
 va_end(ap);
 return res;
}

/** Change log level to increase or decrease verbosity level.
 * \param *swdctx swd context.
 * \param loglevel is the target verbosity level to be set.
 * \return SWD_OK on success or error code.
 */

int swd_log_level_set(swd_ctx_t *swdctx, swd_loglevel_t loglevel){
 if (swdctx==NULL) return SWD_ERROR_NULLCONTEXT;
 if (loglevel<SWD_LOGLEVEL_MIN && loglevel>SWD_LOGLEVEL_MAX)
  return SWD_ERROR_LOGLEVEL;

 swdctx->config.loglevel=loglevel;
 swd_log(swdctx, SWD_LOGLEVEL_DEBUG, "SWD_D: SWD LogLevel[%d..%d] set to: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel));
 return SWD_OK;
}

const char *swd_log_level_string(swd_loglevel_t loglevel){
 switch (loglevel){
  case SWD_LOGLEVEL_SILENT: return "SWD_LOGLEVEL_SILENT";
  case SWD_LOGLEVEL_ERROR:  return "SWD_LOGLEVEL_ERROR";
  case SWD_LOGLEVEL_WARNING: return "SWD_LOGLEVEL_WARNING";
  case SWD_LOGLEVEL_NORMAL:  return "SWD_LOGLEVEL_NORMAL";
  case SWD_LOGLEVEL_INFO:    return "SWD_LOGLEVEL_INFO";
  case SWD_LOGLEVEL_DEBUG:   return "SWD_LOGLEVEL_DEBUG";
 }
 return "UNKNOWN LOGLEVEL!";
};


/** @} */

{'fraction_non_alphanumeric': 0.11306042884990253, 'fraction_numerical': 0.004815961472308222, 'mean_word_length': 4.757095709570957, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1826301', 'n_tokens_mistral': 2677, 'n_tokens_neox': 2528, 'n_words': 987}