Blame src/log.h

Packit 8f70b4
/*
Packit 8f70b4
 * lftp - file transfer program
Packit 8f70b4
 *
Packit 8f70b4
 * Copyright (c) 1996-2016 by Alexander V. Lukyanov (lav@yars.free.net)
Packit 8f70b4
 *
Packit 8f70b4
 * This program is free software; you can redistribute it and/or modify
Packit 8f70b4
 * it under the terms of the GNU General Public License as published by
Packit 8f70b4
 * the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
 * (at your option) any later version.
Packit 8f70b4
 *
Packit 8f70b4
 * This program is distributed in the hope that it will be useful,
Packit 8f70b4
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
 * GNU General Public License for more details.
Packit 8f70b4
 *
Packit 8f70b4
 * You should have received a copy of the GNU General Public License
Packit 8f70b4
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 8f70b4
 */
Packit 8f70b4
Packit 8f70b4
#ifndef LOG_H
Packit 8f70b4
#define LOG_H
Packit 8f70b4
Packit 8f70b4
#include <unistd.h>
Packit 8f70b4
#include <stdlib.h>
Packit 8f70b4
#include <stdarg.h>
Packit 8f70b4
#include "Ref.h"
Packit 8f70b4
#include "ResMgr.h"
Packit 8f70b4
Packit 8f70b4
class Log : public ResClient
Packit 8f70b4
{
Packit 8f70b4
   const char *name;
Packit 8f70b4
   int output;
Packit 8f70b4
   bool need_close_output;
Packit 8f70b4
   bool tty;
Packit 8f70b4
   bool show_pid;
Packit 8f70b4
   bool show_time;
Packit 8f70b4
   bool show_context;
Packit 8f70b4
   bool at_line_start;
Packit 8f70b4
   typedef void (*tty_cb_t)();
Packit 8f70b4
   tty_cb_t tty_cb;
Packit 8f70b4
Packit 8f70b4
   void CloseOutput()
Packit 8f70b4
      {
Packit 8f70b4
	 if(need_close_output)
Packit 8f70b4
	    close(output);
Packit 8f70b4
	 output=-1;
Packit 8f70b4
	 need_close_output=false;
Packit 8f70b4
      }
Packit 8f70b4
Packit 8f70b4
   bool enabled;
Packit 8f70b4
   int level;
Packit 8f70b4
Packit 8f70b4
   xstring buf;
Packit 8f70b4
Packit 8f70b4
protected:
Packit 8f70b4
   void SetOutput(int o,bool need_close);
Packit 8f70b4
Packit 8f70b4
public:
Packit 8f70b4
   static Ref<Log> global;
Packit 8f70b4
Packit 8f70b4
   bool WillOutput(int l);
Packit 8f70b4
   void DoWrite(const char *str,int len);
Packit 8f70b4
   void DoWrite(const xstring &str) { DoWrite(str,str.length()); }
Packit 8f70b4
   void Write(int l,const char *str,int len);
Packit 8f70b4
   void Write(int l,const char *str) { Write(l,str,xstrlen(str)); }
Packit 8f70b4
   void Write(int l,const xstring &str) { Write(l,str,str.length()); }
Packit 8f70b4
   void Format(int l,const char *fmt,...) PRINTF_LIKE(3,4);
Packit 8f70b4
   void vFormat(int l,const char *fmt,va_list v);
Packit 8f70b4
Packit 8f70b4
   void SetCB(tty_cb_t cb) { tty_cb=cb; }
Packit 8f70b4
Packit 8f70b4
   bool IsTTY() { return tty; }
Packit 8f70b4
Packit 8f70b4
   Log(const char *name);
Packit 8f70b4
   ~Log();
Packit 8f70b4
Packit 8f70b4
   static void Cleanup();
Packit 8f70b4
Packit 8f70b4
   const char *ResPrefix() const { return "log"; }
Packit 8f70b4
   const char *ResClosure() const { return name; }
Packit 8f70b4
   void Reconfig(const char *);
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
#define debug(a) do { if(Log::global) Log::global->Format a; } while(0)
Packit 8f70b4
Packit 8f70b4
#endif // LOG_H