daily - A LevelDB based logging system
npm install daily
1. start a server
Start a server, with default settings (port: 10200, address: 0.0.0.0, location: ./daily.db)
$ daily server
2. create a client and log
var daily = ;// Open a connection to the daily servervar client = ;// By default the log-levels range from 1 to 5, where log level 1 will live// the longest so this should be used for the most critical errors.client;// Close the connectionclient;
3. read the logs
Read logs over the last one hour (3600 seconds), you can read more with
$ daily read
daily command [options]help prints this messageread connects to server and read some log entries : defaults-s --start timestamp read starts at this time : 0-e --end timestamp read stops at this time : now-l --levels start,end range of log levels to read : 1,9-p --past seconds special case, read some : 3600seconds intro the past When nooptions is set, -b is used.-c --colors colors will always be used : true-a --address ip:port client will connect to : 127.0.0.1:10200server start a daily server : defaults-d --database path filepath to the log database : ./daily.db-a --address ip:port server will listen to : 0.0.0.0:10200read examplesdaily read --start 0 read all messages in the databasedaily read -c | less -R make search and walkable in colordaily read --levels 1,1 read only level 1 logsserver examplesdaily server -a 0.0.0.0:0 start server on a random port
By default the port that daily use is
10200 you can always specify it by
an argument or option but you can also set it using the
Creates a client instance, the
new keyword can be opmitted.
var daily = ;var client = ;
The client connects to the daily server on the given
one TCP socket or more. When the first connection is made the
will emit and the
callback will be called.
Please note that you don't need to to wait for the
connect event, in order to
log or start a reader. The request will simply be delayed.
Logs a object with
JSON.stringify(subject) along with the log-level. By default
the log-level range from 1 to 5 where 1 is the most citical log.
Here is a simple example, when no
callback any error will be emitted as an
error event on the
client object. You can also specific the time of the
log manually, but its strongly recommended that you don't do that, as it will
likely be confusing later.
Read logs from
end should be a timestamp
in milliseconds (like
Date.now()). However they can also be
null, this means
that will be no limit in the related direction.
nullthen logs from the begining of time will be send
nullthen logs to end of time will be send
levels is an array of two values, there specifies range of levels there
will be send. Meaning only items there matches
levels <= level <= levels
will be send from the daily server.
var inspectpoint = ;// Read logs from the past hour there was logged with level 1, 2, 3 or 4var reader = client// runs util.inspect on each data object;
Please note that the
reader object can emit an
error event and supports the
This will close the client. Under the hood this means both the TCP socket there
logs data and the TCP sockets there reads data will be closed. However as
writeing logs is quite important the TCP socket there logs won't be closed
before all the logs are done. However it will prevent future
calles by throwing.
In effect this means that you can call
client.close() right after
The client as made a connection.
When the client breaks the connection and makes a successful reconnection this event is emitted.
The client is completly closed.
An error occurred, this can either be related to a TCP connection or a
client.log() call there did not have a
Creates a new server instance, the
new keyword can be opmitted.
var path = ;var daily = ;var server = daily;
Attach the server to a given port and address when the server is ready, the
listening event will be emitted and the
callback called. If you want a
random port, use
0 as port argument.
Returns the standard TCP address object for the underlying server. For default settings the result will be:
'address' '0.0.0.0''family' 'IPv4''port': 10200
Close the server and all the connections currently active.
This is an example on a very simple error handling.
This is purely for debugging purposes, you should never need to handle the TCP sockets your self. The server will do that internally.
Emits when the server is listening, to know on what port and address use
Emits when the server is closed.
Emits when an error ocure, normally the server won't close because of this. But
it is recomended that you call
Behind this module is a couple of low-level modules that you might need if you which create you own daily module.
The software is license under "MIT"
Copyright (c) 2013 Andreas Madsen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.