-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dlogger.hh
58 lines (48 loc) · 1.24 KB
/
Dlogger.hh
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
//
// Copyright 2009-2017 M. Shulhan (ms@kilabit.info). All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _LIBVOS_DLOGGER_HH
#define _LIBVOS_DLOGGER_HH 1
#include "File.hh"
#include "Locker.hh"
namespace vos {
/**
* Class Dlogger is a module for writing formatted output log to a file or
* standard error, or both. If Dlogger object is not initialized, by calling
* open(), all log output from calling er() or it() will be printed to standard
* error.
*
* Field _max_size define maximum log file size.
*/
class Dlogger : public File {
public:
static const char* __CNAME;
Dlogger();
~Dlogger();
Error open(const char* logfile, size_t max_size = 0
, const char* prefix = 0
, int show_timestamp = 1);
void close();
Error er(const char* fmt, ...);
Error out(const char* fmt, ...);
Error it(const char* fmt, ...);
private:
Dlogger(const Dlogger&);
void operator=(const Dlogger&);
void add_timestamp();
void add_prefix();
Error _w(int fd, const char* fmt);
Locker _locker;
Buffer _tmp;
Buffer _prefix;
time_t _time_s;
struct tm _time;
int _time_show;
va_list _args;
size_t _max_size;
};
} // namespace::vos
#endif
// vi: ts=8 sw=8 tw=80: