-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "show loggging" command to show the most recent log lines. (Also …
…added logging output to "show system")
- Loading branch information
Showing
8 changed files
with
352 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2006-2013 Shane Mc Cormack | ||
* | ||
* 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. | ||
*/ | ||
package com.dfbnc.commands.show; | ||
|
||
import java.text.SimpleDateFormat; | ||
|
||
import com.dfbnc.DFBnc; | ||
import com.dfbnc.commands.AdminCommand; | ||
import com.dfbnc.commands.CommandManager; | ||
import com.dfbnc.commands.CommandOutput; | ||
import com.dfbnc.sockets.UserSocket; | ||
import com.dfbnc.util.RollingWriter; | ||
|
||
/** | ||
* This file represents the 'logging' show command | ||
*/ | ||
public class LoggingCommand extends AdminCommand { | ||
/** | ||
* Handle a Logging command. | ||
* | ||
* @param user the UserSocket that performed this command | ||
* @param params Params for command (param 0 is the command name) | ||
* @param output CommandOutput where output from this command should go. | ||
*/ | ||
@Override | ||
public void handle(final UserSocket user, final String[] params, final CommandOutput output) { | ||
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
final RollingWriter rw = DFBnc.getBNC().getRollingWriter(); | ||
output.sendBotMessage("Most recent " + rw.size() + " (Max: " + rw.getCapacity() + ") log entries: "); | ||
output.sendBotMessage(""); | ||
for (final String line : rw) { | ||
output.sendBotMessage(" " + line); | ||
} | ||
} | ||
|
||
/** | ||
* What does this Command handle. | ||
* | ||
* @return String[] with the names of the tokens we handle. | ||
*/ | ||
@Override | ||
public String[] handles() { | ||
return new String[]{"logging", "*logs"}; | ||
} | ||
|
||
/** | ||
* Create a new instance of the Command Object | ||
* | ||
* @param manager CommandManager that is in charge of this Command | ||
*/ | ||
public LoggingCommand (final CommandManager manager) { super(manager); } | ||
|
||
/** | ||
* Get a description of what this command does | ||
* | ||
* @param command The command to describe (incase one Command does multiple | ||
* things under different names) | ||
* @return A description of what this command does | ||
*/ | ||
@Override | ||
public String getDescription(final String command) { | ||
return "This command shows you the last few lines of system logging output"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2015 Shane Mc Cormack <shanemcc@gmail.com>. | ||
* See LICENSE.txt for licensing details. | ||
*/ | ||
|
||
package com.dfbnc.util; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Writer that adds lines to multiple writers. | ||
* | ||
* @author Shane Mc Cormack <shanemcc@gmail.com> | ||
*/ | ||
public class MultiWriter extends Writer { | ||
|
||
/** List of lines that have been written to this BufferedWriter. */ | ||
private final List<Writer> writers = new LinkedList<>(); | ||
|
||
/** | ||
* Create a new MultiWriter. | ||
*/ | ||
public MultiWriter() { } | ||
|
||
/** | ||
* Add the given writer to the list of writers. | ||
* | ||
* @param writer Writer to add. | ||
*/ | ||
public void addWriter(final Writer writer) { | ||
writers.add(writer); | ||
} | ||
|
||
/** | ||
* Remove the given writer from the list of writers. | ||
* NOTE: This will not close the writer. | ||
* | ||
* @param writer Writer to add. | ||
*/ | ||
public void removeWriter(final Writer writer) { | ||
writers.remove(writer); | ||
} | ||
|
||
@Override | ||
public void write(char[] cbuf, int off, int len) throws IOException { | ||
for (final Writer w : writers) { w.write(cbuf, off, len); } | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
for (final Writer w : writers) { w.flush(); } | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
for (final Writer w : writers) { w.close(); } | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.