/
README
185 lines (131 loc) · 6.5 KB
/
README
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
NAME
Pye::MongoDB - Log with Pye on top of MongoDB
SYNOPSIS
use Pye::MongoDB;
my $pye = Pye::MongoDB->new(
host => 'mongodb://logserver1:27017,logserver2:27017',
find_master => 1,
database => 'log_db',
collection => 'myapp_log'
);
# now start logging
$pye->log($session_id, "Some log message", { data => 'example data' });
# inspect the logs from the command line
pye -b MongoDB -d log_db -c myapp_log
DESCRIPTION
This package provides a MongoDB backend for the Pye logging system. This
is currently the easiest backend to use, since no setup is needed in
order to start logging with it.
Messages will be stored in a MongoDB database with the following keys:
* "session_id" - the session ID, a string, always exists
* "date" - the date the messages was logged, in ISODate format, always
exists
* "text" - the text of the message, a string, always exists
* "data" - supplemental JSON structure, optional
An index on the "session_id" field will automatically be created.
NOTES AND RECOMMENDATIONS
As of this writing (MongoDB v2.6), MongoDB is kind of a storage guzzler.
You might find it useful to create a TTL index on the log collection.
For example, the following line (entered into the "mongo" shell) will
create a time-to-live index of 2 days on a log collection:
db.log_collection.ensureIndex({ date: 1 }, { expireAfterSeconds: 172800 })
Alternatively, you could make the collection capped and limit it by
size. Note, however, that the _remove_session_logs() method will not
work in that case.
Also, consider using TokuMX as a drop-in replacement for MongoDB. It it
faster, uses much less storage space and supports ACID transactions.
USING THE pye COMMAND LINE UTILITY
The pye command line utility, used to inspect logs, provides all command
line options to the "new( [ %options ] )" constructor, which in turn
passes anything to MongoDB::MongoClient. This means that if your
database has replication, or requires authentication, you can provide
these options from the command line.
For example:
pye -b MongoDB
--host mongodb://server1:27017,server2:27017
--find_master=1
-d log_db
-c myapp_log
--username log_user
--password very_secret
"host", "find_master", "username" and "password" in this example will be
passed to "MongoDB::MongoClient".
CONSTRUCTOR
new( [ %options ] )
Create a new instance of this class. All options are optional.
* database - the name of the database, defaults to "logs"
* collection (or table) - the name of the collection, defaults to
"logs"
* be_safe - whether to enable the "safe" flag when inserting log
messages, defaults to a false value
Any other option you provide will be passed to MongoDB::MongoClient, so
pass anything needed in order to connect to the database server (such as
"host", "find_master", etc.).
OBJECT METHODS
The following methods implement the Pye role, so you should refer to
"Pye" for their documentation. Some methods, however, have some
MongoDB-specific notes, so keep reading.
log( $session_id, $text, [ \%data ] )
If "\%data" is provided, this module will traverse it recursively,
replacing any hash-key that contains dots with semicolons, as MongoDB
does not support dots in field names.
session_log( $session_id )
list_sessions( [ \%opts ] )
Takes all options defined by Pye. The "sort" option, however, takes a
MongoDB sorting definition, that is a hash-ref, e.g. "{ _id => 1 }".
This will default to "{ date => -1 }".
CONFIGURATION AND ENVIRONMENT
"Pye::MongoDB" requires no configuration files or environment variables.
DEPENDENCIES
"Pye::MongoDB" depends on the following CPAN modules:
* version
* Carp
* MongoDB
* Pye
* Role::Tiny
* Tie::IxHash
BUGS AND LIMITATIONS
Please report any bugs or feature requests to
"bug-Pye-MongoDB@rt.cpan.org", or through the web interface at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Pye-MongoDB>.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Pye::MongoDB
You can also look for information at:
* RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Pye-MongoDB>
* AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Pye-MongoDB>
* CPAN Ratings
<http://cpanratings.perl.org/d/Pye-MongoDB>
* Search CPAN
<http://search.cpan.org/dist/Pye-MongoDB/>
AUTHOR
Ido Perlmuter <ido@ido50.net>
LICENSE AND COPYRIGHT
Copyright (c) 2015, Ido Perlmuter "ido@ido50.net".
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either version 5.8.1 or any later
version. See perlartistic and perlgpl.
The full text of the license can be found in the LICENSE file included
with this module.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.