Search in sources :

Example 16 with PmsConfiguration

use of net.pms.configuration.PmsConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class FileUtilTest method setUp.

/**
 * Set up testing conditions before running the tests.
 * @throws ConfigurationException
 */
@Before
public final void setUp() throws ConfigurationException {
    // Silence all log messages from the PMS code that is being tested
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.getLogger(Logger.ROOT_LOGGER_NAME).setLevel(Level.OFF);
    ;
    PMS.get();
    PMS.setConfiguration(new PmsConfiguration(false));
}
Also used : PmsConfiguration(net.pms.configuration.PmsConfiguration) LoggerContext(ch.qos.logback.classic.LoggerContext) Before(org.junit.Before)

Example 17 with PmsConfiguration

use of net.pms.configuration.PmsConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class LoggingConfig method setConfigurableFilters.

private static synchronized void setConfigurableFilters(boolean setConsole, boolean setTraces) {
    PmsConfiguration configuration = PMS.getConfiguration();
    if (loggerContext == null) {
        LOGGER.error("Unknown loggerContext, aborting buffered logging. Make sure that loadFile() has been called first.");
        return;
    }
    if (setConsole) {
        Level level = configuration.getLoggingFilterConsole();
        if (consoleLevel == null || consoleLevel != level) {
            consoleLevel = level;
        } else {
            setConsole = false;
        }
    }
    if (setTraces) {
        Level level = configuration.getLoggingFilterLogsTab();
        if (tracesLevel == null || tracesLevel != level) {
            tracesLevel = level;
        } else {
            setTraces = false;
        }
    }
    if (setConsole || setTraces) {
        // Since Console- and FrameAppender will exist at root level and won't be detached by syslog,
        // there's no reason to build an iterator as this should suffice.
        Iterator<Appender<ILoggingEvent>> it = CacheLogger.isActive() ? CacheLogger.iteratorForAppenders() : rootLogger.iteratorForAppenders();
        while (it.hasNext()) {
            Appender<ILoggingEvent> appender = it.next();
            if (setConsole && appender instanceof ConsoleAppender) {
                ConsoleAppender<ILoggingEvent> ca = (ConsoleAppender<ILoggingEvent>) appender;
                boolean createNew = true;
                if (!ca.getCopyOfAttachedFiltersList().isEmpty()) {
                    for (Filter<ILoggingEvent> filter : ca.getCopyOfAttachedFiltersList()) {
                        if (filter instanceof ThresholdFilter) {
                            createNew = false;
                            ((ThresholdFilter) filter).setLevel(consoleLevel.levelStr);
                            ((ThresholdFilter) filter).start();
                        }
                    }
                }
                if (createNew) {
                    ThresholdFilter consoleFilter = new ThresholdFilter();
                    ca.addFilter(consoleFilter);
                    consoleFilter.setLevel(consoleLevel.levelStr);
                    consoleFilter.setContext(loggerContext);
                    consoleFilter.start();
                }
            }
            if (setTraces && appender instanceof FrameAppender) {
                FrameAppender<ILoggingEvent> fa = (FrameAppender<ILoggingEvent>) appender;
                boolean createNew = true;
                if (!fa.getCopyOfAttachedFiltersList().isEmpty()) {
                    for (Filter<ILoggingEvent> filter : fa.getCopyOfAttachedFiltersList()) {
                        if (filter instanceof ThresholdFilter) {
                            createNew = false;
                            ((ThresholdFilter) filter).setLevel(tracesLevel.levelStr);
                            ((ThresholdFilter) filter).start();
                        }
                    }
                }
                if (createNew) {
                    ThresholdFilter tracesFilter = new ThresholdFilter();
                    fa.addFilter(tracesFilter);
                    tracesFilter.setLevel(tracesLevel.levelStr);
                    tracesFilter.setContext(loggerContext);
                    tracesFilter.start();
                }
            }
        }
    }
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) OutputStreamAppender(ch.qos.logback.core.OutputStreamAppender) FileAppender(ch.qos.logback.core.FileAppender) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) Appender(ch.qos.logback.core.Appender) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) PmsConfiguration(net.pms.configuration.PmsConfiguration) Level(ch.qos.logback.classic.Level)

Example 18 with PmsConfiguration

use of net.pms.configuration.PmsConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class LoggingConfig method setSyslog.

/**
 * Adds/modifies/removes a syslog appender based on PmsConfiguration and
 * disables/enables file appenders for easier access to syslog logging for
 * users without in-depth knowledge of LogBack. Stops file appenders if
 * syslog is started and vice versa.<P>
 *
 * Must be called after {@link #loadFile()} and after UMS configuration is
 * loaded.
 */
public static synchronized void setSyslog() {
    ActionType action = ActionType.NONE;
    PmsConfiguration configuration = PMS.getConfiguration();
    if (loggerContext == null) {
        LOGGER.error("Unknown loggerContext, aborting syslog configuration. Make sure that loadFile() has been called first.");
        return;
    } else if (syslogDisabled) {
        // Only create a new syslog appender if there's no syslog appender configured already
        LOGGER.warn("A syslog appender is already configured, aborting syslog configuration");
        return;
    }
    if (configuration.getLoggingUseSyslog()) {
        // Check for valid parameters
        if (configuration.getLoggingSyslogHost().isEmpty()) {
            LOGGER.error("Empty syslog hostname, syslog configuration aborted");
            return;
        }
        try {
            InetAddress.getByName(configuration.getLoggingSyslogHost());
        } catch (UnknownHostException e) {
            LOGGER.error("Unknown syslog hostname {}, syslog configuration aborted", configuration.getLoggingSyslogHost());
            return;
        }
        if (configuration.getLoggingSyslogPort() < 1 && configuration.getLoggingSyslogPort() > 65535) {
            LOGGER.error("Invalid syslog port {}, using default", configuration.getLoggingSyslogPort());
            configuration.setLoggingSyslogPortDefault();
        }
        if (!configuration.getLoggingSyslogFacility().toLowerCase().matches("auth|authpriv|daemon|cron|ftp|lpr|kern|mail|news|syslog|user|" + "uucp|local0|local1|local2|local3|local4|local5|local6|local7")) {
            LOGGER.error("Invalid syslog facility \"{}\", using default", configuration.getLoggingSyslogFacility());
            configuration.setLoggingSyslogFacilityDefault();
        }
    }
    if (configuration.getLoggingUseSyslog() && syslog == null) {
        syslog = new SyslogAppender();
        syslog.setContext(loggerContext);
        syslog.setSuffixPattern("UMS [%thread] %msg");
        syslog.setName("UMS syslog");
        syslog.setCharset(StandardCharsets.UTF_8);
        action = ActionType.START;
    } else if (!configuration.getLoggingUseSyslog() && syslog != null) {
        action = ActionType.STOP;
    }
    if (syslog != null && (action == ActionType.START || action == ActionType.NONE)) {
        syslog.setSyslogHost(configuration.getLoggingSyslogHost());
        syslog.setPort(configuration.getLoggingSyslogPort());
        syslog.setFacility(configuration.getLoggingSyslogFacility().toUpperCase());
        syslog.start();
    }
    if (action == ActionType.START || action == ActionType.STOP) {
        Iterator<Appender<ILoggingEvent>> it = CacheLogger.isActive() ? CacheLogger.iteratorForAppenders() : rootLogger.iteratorForAppenders();
        while (it.hasNext()) {
            Appender<ILoggingEvent> appender = it.next();
            if (action == ActionType.START && appender instanceof FileAppender) {
                if (CacheLogger.isActive()) {
                    CacheLogger.removeAppender(appender);
                } else {
                    rootLogger.detachAppender(appender);
                }
                syslogDetachedAppenders.add(appender);
                // If syslog is disabled later and this appender reactivated, append to the file instead of truncate
                ((FileAppender<ILoggingEvent>) appender).setAppend(true);
            } else if (action == ActionType.STOP && appender == syslog) {
                if (CacheLogger.isActive()) {
                    CacheLogger.removeAppender(syslog);
                } else {
                    rootLogger.detachAppender(syslog);
                }
                syslog.stop();
                syslog = null;
            }
        }
        if (action == ActionType.START) {
            if (CacheLogger.isActive()) {
                CacheLogger.addAppender(syslog);
            } else {
                rootLogger.addAppender(syslog);
            }
            LOGGER.info("Syslog logging started, file logging disabled");
        } else {
            it = syslogDetachedAppenders.iterator();
            while (it.hasNext()) {
                Appender<ILoggingEvent> appender = it.next();
                if (CacheLogger.isActive()) {
                    CacheLogger.addAppender(appender);
                } else {
                    rootLogger.addAppender(appender);
                }
            }
            syslogDetachedAppenders.clear();
            LOGGER.info("Syslog logging stopped, file logging enabled");
        }
    }
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) OutputStreamAppender(ch.qos.logback.core.OutputStreamAppender) FileAppender(ch.qos.logback.core.FileAppender) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) UnknownHostException(java.net.UnknownHostException) PmsConfiguration(net.pms.configuration.PmsConfiguration) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 19 with PmsConfiguration

use of net.pms.configuration.PmsConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class HTMLConsole method servePage.

public static String servePage(String resource) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head><title>").append(PropertiesUtil.getProjectProperties().get("project.name")).append(" HTML Console</title></head><body>");
    DLNAMediaDatabase database = PMS.get().getDatabase();
    PmsConfiguration configuration = PMS.getConfiguration();
    if (resource.equals("scan") && configuration.getUseCache()) {
        if (!database.isScanLibraryRunning()) {
            database.scanLibrary();
        }
        if (database.isScanLibraryRunning()) {
            sb.append("<p align=center><b>Scan in progress! you can also <a href=\"stop\">stop it</a></b></p><br>");
        }
    }
    if (resource.equals("stop") && configuration.getUseCache() && database.isScanLibraryRunning()) {
        database.stopScanLibrary();
        sb.append("<p align=center><b>Scan stopped!</b></p><br>");
    }
    sb.append("<p align=center><img src='/images/logo.png'><br>").append(PropertiesUtil.getProjectProperties().get("project.name")).append(" HTML console<br><br>Menu:<br>");
    sb.append("<a href=\"home\">Home</a><br>");
    sb.append("<a href=\"scan\">Scan folders</a><br>");
    sb.append("</p></body></html>");
    return sb.toString();
}
Also used : PmsConfiguration(net.pms.configuration.PmsConfiguration) DLNAMediaDatabase(net.pms.dlna.DLNAMediaDatabase)

Example 20 with PmsConfiguration

use of net.pms.configuration.PmsConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class RAW method parse.

@Override
public void parse(DLNAMediaInfo media, InputFile file, int type, RendererConfiguration renderer) {
    boolean trace = LOGGER.isTraceEnabled();
    if (media == null || file == null || file.getFile() == null) {
        // Parsing is impossible
        if (trace) {
            if (file != null && file.getFile() != null) {
                LOGGER.trace("Not parsing RAW file \"{}\" because media is null", file.getFile().getName());
            } else {
                LOGGER.error("Not parsing RAW file because file is null");
            }
        }
        return;
    }
    PmsConfiguration configuration = PMS.getConfiguration(renderer);
    try {
        // Only parse using DCRaw if it is enabled
        DCRaw dcraw = (DCRaw) PlayerFactory.getEnabledPlayer(DCRaw.class, this);
        if (dcraw != null) {
            if (trace) {
                LOGGER.trace("Parsing RAW image \"{}\" with DCRaw", file.getFile().getName());
            }
            dcraw.parse(media, file.getFile());
            media.setCodecV(FormatConfiguration.RAW);
            media.setContainer(FormatConfiguration.RAW);
            ImageInfo imageInfo = null;
            Metadata metadata = null;
            FileType fileType = null;
            try (BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(file.getFile().toPath()))) {
                fileType = FileTypeDetector.detectFileType(inputStream);
                metadata = ImagesUtil.getMetadata(inputStream, fileType);
            } catch (IOException e) {
                metadata = new Metadata();
                LOGGER.debug("Error reading \"{}\": {}", file.getFile().getAbsolutePath(), e.getMessage());
                LOGGER.trace("", e);
            } catch (ImageProcessingException e) {
                metadata = new Metadata();
                LOGGER.debug("Error parsing {} metadata for \"{}\": {}", fileType.toString().toUpperCase(Locale.ROOT), file.getFile().getAbsolutePath(), e.getMessage());
                LOGGER.trace("", e);
            }
            if (fileType == FileType.Arw && !ImagesUtil.isARW(metadata)) {
                fileType = FileType.Tiff;
            }
            ImageFormat format = ImageFormat.toImageFormat(fileType);
            if (format == null || format == ImageFormat.TIFF) {
                format = ImageFormat.toImageFormat(metadata);
                if (format == null || format == ImageFormat.TIFF) {
                    format = ImageFormat.RAW;
                }
            }
            try {
                imageInfo = ImageInfo.create(media.getWidth(), media.getHeight(), metadata, format, file.getSize(), true, false);
                if (trace) {
                    LOGGER.trace("Parsing of RAW image \"{}\" completed: {}", file.getFile().getName(), imageInfo);
                }
            } catch (ParseException e) {
                LOGGER.warn("Unable to parse \"{}\": {}", file.getFile().getAbsolutePath(), e.getMessage());
                LOGGER.trace("", e);
            }
            media.setImageInfo(imageInfo);
            if (media.getWidth() > 0 && media.getHeight() > 0 && configuration.getImageThumbnailsEnabled()) {
                byte[] image = new DCRaw().getThumbnail(null, file.getFile().getAbsolutePath(), imageInfo);
                media.setThumb(DLNAThumbnail.toThumbnail(image, 320, 320, ScaleType.MAX, ImageFormat.JPEG, false));
            }
        } else {
            if (trace) {
                LOGGER.trace("Parsing RAW image \"{}\" as a regular image because DCRaw is disabled", file.getFile().getName());
            }
            ImagesUtil.parseImage(file.getFile(), media);
        }
        media.setSize(file.getSize());
        media.setImageCount(1);
        media.postParse(type, file);
        media.setMediaparsed(true);
    } catch (IOException e) {
        LOGGER.error("Error parsing RAW file \"{}\": {}", file.getFile().getAbsolutePath(), e.getMessage());
        LOGGER.trace("", e);
    }
}
Also used : ImageProcessingException(com.drew.imaging.ImageProcessingException) DCRaw(net.pms.encoders.DCRaw) PmsConfiguration(net.pms.configuration.PmsConfiguration) FileType(com.drew.imaging.FileType) BufferedInputStream(java.io.BufferedInputStream) Metadata(com.drew.metadata.Metadata) IOException(java.io.IOException) ParseException(net.pms.util.ParseException) ImageInfo(net.pms.image.ImageInfo) ImageFormat(net.pms.image.ImageFormat)

Aggregations

PmsConfiguration (net.pms.configuration.PmsConfiguration)32 File (java.io.File)7 ProcessWrapperImpl (net.pms.io.ProcessWrapperImpl)7 ArrayList (java.util.ArrayList)6 OutputParams (net.pms.io.OutputParams)5 IOException (java.io.IOException)4 ProcessWrapper (net.pms.io.ProcessWrapper)4 LoggerContext (ch.qos.logback.classic.LoggerContext)3 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)3 Appender (ch.qos.logback.core.Appender)3 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)3 FileAppender (ch.qos.logback.core.FileAppender)3 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)3 RendererConfiguration (net.pms.configuration.RendererConfiguration)3 PipeProcess (net.pms.io.PipeProcess)3 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)2 PrintWriter (java.io.PrintWriter)2 StringTokenizer (java.util.StringTokenizer)2 DLNAMediaAudio (net.pms.dlna.DLNAMediaAudio)2