summaryrefslogtreecommitdiff
path: root/src/log/Log.h
blob: 5a378e929eeea1f2d22f58f09b72cf327b9525bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef __CEPH_LOG_LOG_H
#define __CEPH_LOG_LOG_H

#include <pthread.h>

#include "common/Thread.h"

#include "Entry.h"
#include "EntryQueue.h"
#include "SubsystemMap.h"

namespace ceph {
namespace log {

class Log : private Thread
{
  Log **m_indirect_this;

  SubsystemMap *m_subs;
  
  pthread_spinlock_t m_lock;
  pthread_mutex_t m_queue_mutex;
  pthread_mutex_t m_flush_mutex;
  pthread_cond_t m_cond;

  EntryQueue m_new;    ///< new entries
  EntryQueue m_recent; ///< recent (less new) entries we've already written at low detail

  std::string m_log_file;
  int m_fd;

  int m_syslog_log, m_syslog_crash;
  int m_stderr_log, m_stderr_crash;

  bool m_stop;

  int m_max_new, m_max_recent;

  void *entry();

  void _flush(EntryQueue *q, EntryQueue *requeue, bool crash);

  void _log_message(const char *s, bool crash);

public:
  Log(SubsystemMap *s);
  virtual ~Log();

  void set_flush_on_exit();

  void set_max_new(int n);
  void set_max_recent(int n);
  void set_log_file(std::string fn);
  void reopen_log_file();

  void flush(); 

  void dump_recent();

  void set_syslog_level(int log, int crash);
  void set_stderr_level(int log, int crash);

  Entry *create_entry(int level, int subsys);
  void submit_entry(Entry *e);

  void start();
  void stop();
};

}
}

#endif