Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions priv/static/phoenix_live_reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ let pageStrategy = channel => {
window[targetWindow].location.reload()
}

const elixirLogLevels = [
"emergency",
"alert",
"critical",
"error",
"warning",
"notice" ,
"info",
"debug"
]

let reloadStrategies = {
css: reloadPageOnCssChanges ? pageStrategy : cssStrategy,
page: pageStrategy
Expand All @@ -51,6 +62,7 @@ class LiveReloader {
constructor(socket){
this.socket = socket
this.logsEnabled = false
this.minLogLevel = "debug"
this.enabledOnce = false
this.editorURL = null
}
Expand All @@ -70,7 +82,7 @@ class LiveReloader {
let reloadStrategy = reloadStrategies[msg.asset_type] || reloadStrategies.page
setTimeout(() => reloadStrategy(this.channel), interval)
})
this.channel.on("log", ({msg, level}) => this.logsEnabled && this.log(level, msg))
this.channel.on("log", ({msg, level}) => this.logsEnabled && this.isMinLogLevel(level) && this.log(level, msg))
this.channel.join().receive("ok", ({editor_url}) => {
this.editorURL = editor_url
})
Expand All @@ -82,9 +94,16 @@ class LiveReloader {
socket.disconnect()
}

enableServerLogs(){ this.logsEnabled = true }
enableServerLogs(level = this.minLogLevel){
this.logsEnabled = true
this.minLogLevel = level
}
disableServerLogs(){ this.logsEnabled = false }

isMinLogLevel(level){
return elixirLogLevels.indexOf(level) <= elixirLogLevels.indexOf(this.minLogLevel)
}

openEditorAtCaller(targetNode){
if(!this.editorURL){
return console.error("phoenix_live_reload cannot openEditorAtCaller without configured PLUG_EDITOR")
Expand Down