changeset 144:5ed0c78a6785

Plugin logger: use new format section, #410 Also fix various issues: - Parameter file is incorrect, - Formats were not loaded.
author David Demelier <markand@malikania.fr>
date Thu, 19 May 2016 22:03:53 +0200
parents 11113212576c
children 410f71eb9237
files plugins/logger/logger.js plugins/logger/logger.md
diffstat 2 files changed, 60 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/logger/logger.js	Thu May 19 21:17:50 2016 +0200
+++ b/plugins/logger/logger.js	Thu May 19 22:03:53 2016 +0200
@@ -16,14 +16,14 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* Modules */
+// Modules.
 var Directory	= Irccd.Directory;
 var File	= Irccd.File;
 var Logger	= Irccd.Logger;
 var Plugin	= Irccd.Plugin;
 var Util	= Irccd.Util;
 
-/* Plugin information */
+// Plugin information.
 info = {
 	author: "David Demelier <markand@malikania.fr>",
 	license: "ISC",
@@ -34,7 +34,7 @@
 /**
  * All available formats.
  */
-var formats = {
+Plugin.format = {
 	"cmode":	"%H:%M:%S :: #{nickname} changed the mode to: #{mode} #{arg}",
 	"cnotice":	"%H:%M:%S :: [notice] (#{channel}) #{nickname}: #{message}",
 	"join":		"%H:%M:%S >> #{nickname} joined #{channel}",
@@ -53,7 +53,16 @@
  */
 function loadFormats()
 {
-	for (var key in formats) {
+	// --- DEPRECATED ------------------------------------------
+	//
+	// This code will be removed.
+	//
+	// Since:	2.1.0
+	// Until:	3.0.0
+	// Reason:	new [format] section replaces it.
+	//
+	// ----------------------------------------------------------
+	for (var key in Plugin.format) {
 		var optname = "format-" + key;
 
 		if (typeof (Plugin.config[optname]) !== "string")
@@ -62,7 +71,7 @@
 		if (Plugin.config[optname].length === 0)
 			Logger.warning("skipping empty '" + optname + "' format");
 		else
-			formats[key] = Plugin.config[optname];
+			Plugin.format[key] = Plugin.config[optname];
 	}
 }
 
@@ -94,7 +103,7 @@
 
 	Logger.debug("opening: " + path);
 
-	var str = Util.format(formats[fmt], args);
+	var str = Util.format(Plugin.format[fmt], args);
 	var file = new File(path, "wa");
 
 	file.write(str + "\n");
@@ -104,6 +113,13 @@
 {
 	if (Plugin.config["path"] === undefined)
 		throw new Error("Missing 'path' option");
+
+	loadFormats();
+}
+
+function onReload()
+{
+	loadFormats();
 }
 
 function onChannelMode(server, origin, channel, mode, arg)
--- a/plugins/logger/logger.md	Thu May 19 21:17:50 2016 +0200
+++ b/plugins/logger/logger.md	Thu May 19 22:03:53 2016 +0200
@@ -32,11 +32,28 @@
 
 ## Configuration
 
-The plugin **logger** can be configured to format logs and to use different log path.
-
 The following options are available under the `[plugin.logger]` section:
 
-  - **file**: (string) the path to the file where to store logs,
+  - **path**: (string) the path to the file where to store logs,
+
+**Deprecated in irccd 2.1.0:**
+
+  - **format-cmode**: Use `[format.logger] cmode` instead,
+  - **format-cnotice**: Use `[format.logger] cnotice` instead,
+  - **format-join**: Use `[format.logger] join` instead,
+  - **format-kick**: Use `[format.logger] kick` instead,
+  - **format-me**: Use `[format.logger] me` instead,
+  - **format-message**: Use `[format.logger] message` instead,
+  - **format-mode**: Use `[format.logger] mode` instead,
+  - **format-notice**: Use `[format.logger] notice` instead,
+  - **format-part**: Use `[format.logger] part` instead,
+  - **format-query**: Use `[format.logger] query` instead,
+  - **format-topic**: Use `[format.logger] topic` instead,
+
+## Formats
+
+The **logger** plugin supports the following formats in `[format.logger]` section:
+
   - **cmode**: (string) format for channel mode change,
   - **cnotice**: (string) format for channel notices,
   - **join**: (string) format when someone joins a channel,
@@ -53,20 +70,20 @@
 
 The following keywords are supported:
 
-| Format                  | Keywords                          | Notes                           |
-|-------------------------|-----------------------------------|---------------------------------|
-| (any)                   | nickname, origin, server, source  | source is the channel or nick   |
-| **format-cmode**        | arg, channel, mode,               | the mode and its arguments      |
-| **format-cnotice**      | channel, message                  | the message notice              |
-| **format-join**         | channel                           |                                 |
-| **format-kick**         | channel, reason, target           |                                 |
-| **format-me**           | channel, message                  | message is the emote action     |
-| **format-message**      | channel, message                  |                                 |
-| **format-mode**         | arg, mode                         | the mode and its arguments      |
-| **format-notice**       | message                           | the notice message              |
-| **format-part**         | channel, reason                   |                                 |
-| **format-query**        | message                           |                                 |
-| **format-topic**        | channel, topic                    |                                 |
+| Format      | Keywords                          | Notes                           |
+|-------------|-----------------------------------|---------------------------------|
+| (any)       | nickname, origin, server, source  | source is the channel or nick   |
+| **cmode**   | arg, channel, mode,               | the mode and its arguments      |
+| **cnotice** | channel, message                  | the message notice              |
+| **join**    | channel                           |                                 |
+| **kick**    | channel, reason, target           |                                 |
+| **me**      | channel, message                  | message is the emote action     |
+| **message** | channel, message                  |                                 |
+| **mode**    | arg, mode                         | the mode and its arguments      |
+| **notice**  | message                           | the notice message              |
+| **part**    | channel, reason                   |                                 |
+| **query**   | message                           |                                 |
+| **topic**   | channel, topic                    |                                 |
 
 The **source** keyword is specially designed to use a generic path for the path parameter.
 
@@ -77,8 +94,10 @@
  <div class="panel-body">
 ````ini
 [plugin.logger]
-file = "/var/log/irccd/#{server}/%y/%m/%d/#{source}.txt"
-format-join = "user #{nickname} joined #{channel}"
+path = "/var/log/irccd/#{server}/%y/%m/%d/#{source}.txt"
+
+[format.logger]
+join = "user #{nickname} joined #{channel}"
 ````
  </div>
 </div>