LCOV - code coverage report
Current view: top level - js/xpconnect/src - XPCLog.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 36 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* vim: set ts=8 sts=4 et sw=4 tw=99: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : /* Debug Logging support. */
       8             : 
       9             : #include "XPCLog.h"
      10             : #include "mozilla/Logging.h"
      11             : #include "mozilla/Sprintf.h"
      12             : #include "mozilla/mozalloc.h"
      13             : #include <string.h>
      14             : #include <stdarg.h>
      15             : 
      16             : // this all only works for DEBUG...
      17             : #ifdef DEBUG
      18             : 
      19             : #define SPACE_COUNT     200
      20             : #define LINE_LEN        200
      21             : #define INDENT_FACTOR   2
      22             : 
      23             : #define CAN_RUN (g_InitState == 1 || (g_InitState == 0 && Init()))
      24             : 
      25             : static char*    g_Spaces;
      26             : static int      g_InitState = 0;
      27             : static int      g_Indent = 0;
      28             : static mozilla::LazyLogModule g_LogMod("xpclog");
      29             : 
      30           0 : static bool Init()
      31             : {
      32           0 :     g_Spaces = new char[SPACE_COUNT+1];
      33           0 :     if (!g_Spaces || !MOZ_LOG_TEST(g_LogMod,LogLevel::Error)) {
      34           0 :         g_InitState = 1;
      35           0 :         XPC_Log_Finish();
      36           0 :         return false;
      37             :     }
      38           0 :     memset(g_Spaces, ' ', SPACE_COUNT);
      39           0 :     g_Spaces[SPACE_COUNT] = 0;
      40           0 :     g_InitState = 1;
      41           0 :     return true;
      42             : }
      43             : 
      44             : void
      45           0 : XPC_Log_Finish()
      46             : {
      47           0 :     if (g_InitState == 1) {
      48           0 :         delete [] g_Spaces;
      49             :     }
      50           0 :     g_InitState = -1;
      51           0 : }
      52             : 
      53             : void
      54           0 : XPC_Log_print(const char* fmt, ...)
      55             : {
      56             :     va_list ap;
      57             :     char line[LINE_LEN];
      58             : 
      59           0 :     va_start(ap, fmt);
      60           0 :     VsprintfLiteral(line, fmt, ap);
      61           0 :     va_end(ap);
      62           0 :     if (g_Indent)
      63           0 :         PR_LogPrint("%s%s",g_Spaces+SPACE_COUNT-(INDENT_FACTOR*g_Indent),line);
      64             :     else
      65           0 :         PR_LogPrint("%s",line);
      66           0 : }
      67             : 
      68             : bool
      69           0 : XPC_Log_Check(int i)
      70             : {
      71           0 :     return CAN_RUN && MOZ_LOG_TEST(g_LogMod,LogLevel::Error);
      72             : }
      73             : 
      74             : void
      75           0 : XPC_Log_Indent()
      76             : {
      77           0 :     if (INDENT_FACTOR*(++g_Indent) > SPACE_COUNT)
      78           0 :         g_Indent-- ;
      79           0 : }
      80             : 
      81             : void
      82           0 : XPC_Log_Outdent()
      83             : {
      84           0 :     if (--g_Indent < 0)
      85           0 :         g_Indent++;
      86           0 : }
      87             : 
      88             : void
      89           0 : XPC_Log_Clear_Indent()
      90             : {
      91           0 :     g_Indent = 0;
      92           0 : }
      93             : 
      94             : #endif

Generated by: LCOV version 1.13