summaryrefslogtreecommitdiff
path: root/TAO/examples/Logging/Logger_i.h
blob: 24850228c14e48baa086544e6bd06fa5e9eb75e4 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// -*- C++ -*-

//=============================================================================
/**
 *  @file   Logger_i.h
 *
 *  $Id$
 *
 *  @author Marina Spivak <marina@cs.wustl.edu>
 *  @author Sergio Flores-Gaitan <sergio@cs.wustl.edu>
 *  @author and Matthew Braun <mjb2@cec.wustl.edu>
 */
//=============================================================================


#ifndef TAO_ORBSVCS_LOGGER_I_H
#define TAO_ORBSVCS_LOGGER_I_H

#include "LoggerS.h"
#include "ace/Hash_Map_Manager.h"
#include "ace/SString.h"
#include "ace/Null_Mutex.h"

/**
 * @class Logger_i
 *
 * @brief Used to log messages to a logging server.
 */
class Logger_i : public virtual POA_Logger
{
public:
  /// constructor
  Logger_i (const char* name);

  /// destructor
  virtual ~Logger_i (void);

  /// Writes the <log_rec> to the standard output.
  virtual void log (const Logger::Log_Record &log_rec);

  /// Writes the <log_rec> to the standard output with the given
  /// verbosity level
  virtual void logv (const Logger::Log_Record &log_rec,
                     Logger::Verbosity_Level verbosity);

  /// Writes the <log_rec> to the standard output.
  virtual void log_twoway (const Logger::Log_Record &log_rec);

  /// Writes the <log_rec> to the standard output with the given
  /// verbosity level
  virtual void logv_twoway (const Logger::Log_Record &log_rec,
                            Logger::Verbosity_Level verbosity);

  /// Sets the verbosity level. Valid values are {VERBOSE, VERBOSE_LITE
  ///  and SILENT}. Defaults to VERBOSE
   void verbosity (Logger::Verbosity_Level level);

private:
  /// Converts the IDL defined <Log_Priority> enum type to the
  /// <ACE_Log_Priority> enum type.
  ACE_Log_Priority priority_conversion (Logger::Log_Priority priority);

  /**
   * Converts the IDL defined <Verbosity_Level> enum type to a u_long,
   * which is used by the <ACE_Log_Record> to distinguish the
   * level of verbosity.
   */
  u_long verbosity_conversion (Logger::Verbosity_Level verbosity_level);

  /// Logger identification.
  char *name_;

  /// Keeps track of what our current verbosity level is.  This can be
  /// reset by the client to a new value at any point.
  Logger::Verbosity_Level verbosity_level_;
};

/**
 * @class Logger_Factory_i
 *
 * @brief Create a <Logger> of type <name>.
 */
class Logger_Factory_i : public virtual POA_Logger_Factory
{
public:
  /// Constructor.
  Logger_Factory_i (void);

  /// Destructor.
  ~Logger_Factory_i (void);

  /**
   * This function returns a logger with name <name>. If <name> is
   * unique, a new logger is created; else, a previously created
   * logger of name <name> is returned
   */
  virtual Logger_ptr make_logger (const char *name);

private:
  /**
   * Calls to <make_logger> will create a new instance of <Logger> and
   * bind into the hash map manager if <name> is unique, else it will
   * return a previously bound entry.
   */
  ACE_Hash_Map_Manager<ACE_CString, Logger_i *, ACE_Null_Mutex> hash_map_;
};

#endif /* TAO_ORBSVCS_LOGGER_I_H */